Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding realtime api #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ Set Macros
}



* Realtime API

Get last 5 critical alerts:

.. code-block: python

realtime.getServices('list',{
'status': 'critical',
'sortType': 'last_hard_state_change',
'order': 'DESC',
'limit': 5 ,
'fields': 'host_name,description,output,last_state_change'
})


Features
--------

Expand Down
10 changes: 10 additions & 0 deletions centreonapi/centreon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from centreonapi.webservice.configuration.hostgroups import HostGroups
from centreonapi.webservice.configuration.command import Commands
from centreonapi.webservice.configuration.resourcecfg import ResourceCFGs
from centreonapi.webservice.configuration.rtdowntime import RTDowntime
from centreonapi.webservice.configuration.realtime import Realtime

from centreonapi.webservice import Webservice


Expand All @@ -27,3 +30,10 @@ def __init__(self, url=None, username=None, password=None, check_ssl=True):
self.hosttemplates = HostTemplates()
self.commands = Commands()
self.resourcecfgs = ResourceCFGs()
self.rtdowntime = RTDowntime()
self.realtime = Realtime()

def auth(self):
ws = Webservice.getInstance()
ws.auth()
return ws
34 changes: 34 additions & 0 deletions centreonapi/webservice/configuration/realtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

import centreonapi.webservice.configuration.common as common
from centreonapi.webservice import Webservice


class Realtime(common.CentreonObject):

def __init__(self):
self.webservice = Webservice.getInstance()

def getServices(self, action, values=None):
"""
Get some services info
More info about values here:
https://documentation.centreon.com/docs/centreon/en/latest/api/api_rest/index.html#service-status
"""
self.realtime_services = self.webservice.centreon_realtime(
action,
'services',
values)
return self.realtime_services

def getHosts(self, action, values=None):
"""
Get some hosts info
More info about values here:
https://documentation.centreon.com/docs/centreon/en/latest/api/api_rest/index.html#host-status
"""
self.realtime_hosts = self.webservice.centreon_realtime(
action,
'hosts',
values)
return self.realtime_hosts
41 changes: 41 additions & 0 deletions centreonapi/webservice/configuration/rtdowntime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

import centreonapi.webservice.configuration.common as common
from centreonapi.webservice import Webservice

class RTDowntime(common.CentreonObject):

def __init__(self):
self.webservice = Webservice.getInstance()
self.__clapi_action = 'RTDOWNTIME'

def add(self,host_name,time_start,time_end,fixed_time,duration,comment,apply_services):
s, e = self.webservice.call_clapi(
'add',
self.__clapi_action,
["HOST",host_name,
time_start,
time_end,
fixed_time,duration,comment,apply_services])
return s, e

def show_host(self,host_name):
s, e = self.webservice.call_clapi(
'show',
self.__clapi_action,
["HOST",host_name])
return s, e

def show_all(self):
s, e = self.webservice.call_clapi(
'show',
self.__clapi_action,
[])
return s, e

def cancel(self,downtime_id):
s, e = self.webservice.call_clapi(
'cancel',
self.__clapi_action,
[downtime_id])
return s, e