From 461c645a48d333329b12b1961e526eb20abeeec9 Mon Sep 17 00:00:00 2001 From: Marcin Szumski Date: Wed, 5 Feb 2020 15:43:40 +1000 Subject: [PATCH 1/5] Adding RTDowntime support --- centreonapi/centreon.py | 1 + .../webservice/configuration/rtdowntime.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 centreonapi/webservice/configuration/rtdowntime.py diff --git a/centreonapi/centreon.py b/centreonapi/centreon.py index 155be6d..6af7043 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -27,3 +27,4 @@ def __init__(self, url=None, username=None, password=None, check_ssl=True): self.hosttemplates = HostTemplates() self.commands = Commands() self.resourcecfgs = ResourceCFGs() + self.rtdowntime = RTDowntime() 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 From b2a1070430c52027d03dc101bda7041a13b6626d Mon Sep 17 00:00:00 2001 From: Marcin Szumski Date: Wed, 5 Feb 2020 16:58:05 +1000 Subject: [PATCH 2/5] adding centreon rtdowntimesupport --- centreonapi/centreon.py | 1 + 1 file changed, 1 insertion(+) diff --git a/centreonapi/centreon.py b/centreonapi/centreon.py index 6af7043..42e9354 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -7,6 +7,7 @@ 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 import Webservice From a8b6b4b6876b97c4c045688b661a1af452adfe5d Mon Sep 17 00:00:00 2001 From: Marcin Szumski Date: Wed, 11 Mar 2020 03:10:32 +1000 Subject: [PATCH 3/5] Adding Centreon::auth() function --- centreonapi/centreon.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/centreonapi/centreon.py b/centreonapi/centreon.py index 42e9354..dc1ae16 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -29,3 +29,8 @@ def __init__(self, url=None, username=None, password=None, check_ssl=True): self.commands = Commands() self.resourcecfgs = ResourceCFGs() self.rtdowntime = RTDowntime() + + def auth(self) + ws = Webservice.getInstance() + ws.auth() + return ws From 4b8b222113d02e96781896da4f4b4aeef9915a51 Mon Sep 17 00:00:00 2001 From: Marcin Szumski Date: Wed, 11 Mar 2020 03:59:26 +1000 Subject: [PATCH 4/5] bug fix --- centreonapi/centreon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreonapi/centreon.py b/centreonapi/centreon.py index dc1ae16..7f0a85e 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -30,7 +30,7 @@ def __init__(self, url=None, username=None, password=None, check_ssl=True): self.resourcecfgs = ResourceCFGs() self.rtdowntime = RTDowntime() - def auth(self) + def auth(self): ws = Webservice.getInstance() ws.auth() return ws From 33ac97d46944adc30434f0b6d023387b4c45c7bb Mon Sep 17 00:00:00 2001 From: Marek Knappe Date: Tue, 24 Mar 2020 19:44:11 +1000 Subject: [PATCH 5/5] Adding realtime api for hosts and services --- README.rst | 16 +++++++++ centreonapi/centreon.py | 3 ++ .../webservice/configuration/realtime.py | 34 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 centreonapi/webservice/configuration/realtime.py 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 7f0a85e..c4dd1e1 100644 --- a/centreonapi/centreon.py +++ b/centreonapi/centreon.py @@ -8,6 +8,8 @@ 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 @@ -29,6 +31,7 @@ def __init__(self, url=None, username=None, password=None, check_ssl=True): self.commands = Commands() self.resourcecfgs = ResourceCFGs() self.rtdowntime = RTDowntime() + self.realtime = Realtime() def auth(self): ws = Webservice.getInstance() 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