diff --git a/README.rst b/README.rst index fcec1ab..8687924 100644 --- a/README.rst +++ b/README.rst @@ -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 -------- diff --git a/centreonapi/centreon.py b/centreonapi/centreon.py index 155be6d..c4dd1e1 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -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 @@ -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 diff --git a/centreonapi/webservice/configuration/realtime.py b/centreonapi/webservice/configuration/realtime.py new file mode 100644 index 0000000..c310f4f --- /dev/null +++ b/centreonapi/webservice/configuration/realtime.py @@ -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 \ No newline at end of file diff --git a/centreonapi/webservice/configuration/rtdowntime.py b/centreonapi/webservice/configuration/rtdowntime.py new file mode 100644 index 0000000..72ada6a --- /dev/null +++ b/centreonapi/webservice/configuration/rtdowntime.py @@ -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