From 9c304ade5f47473b3e01b78d6e72efd74f7a72a4 Mon Sep 17 00:00:00 2001 From: aleskxyz <39186039+aleskxyz@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:53:52 +0100 Subject: [PATCH 1/2] Return value of check_for_error Fix return value of check_for_error function to send false instead of None --- Nagstamon/Servers/Generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nagstamon/Servers/Generic.py b/Nagstamon/Servers/Generic.py index c541c1320..c832cf451 100644 --- a/Nagstamon/Servers/Generic.py +++ b/Nagstamon/Servers/Generic.py @@ -1706,7 +1706,7 @@ def check_for_error(result, error, status_code) -> Optional[Result]: error=copy.deepcopy(error), status_code=copy.deepcopy(status_code)) else: - return None + return False def get_worst_status_current(self): """ From 6dffdf58cd0c132329a864051d657d12a072ccc6 Mon Sep 17 00:00:00 2001 From: Alireza Eskandari Date: Mon, 30 Oct 2023 16:33:42 +0100 Subject: [PATCH 2/2] refactor return value of check_for_error to None --- Nagstamon/Servers/Alertmanager/alertmanagerserver.py | 2 +- Nagstamon/Servers/Centreon/CentreonLegacy.py | 10 +++++----- Nagstamon/Servers/Generic.py | 6 +++--- Nagstamon/Servers/Icinga.py | 8 ++++---- Nagstamon/Servers/IcingaDBWeb.py | 2 +- Nagstamon/Servers/IcingaDBWebNotifications.py | 2 +- Nagstamon/Servers/Opsview.py | 2 +- Nagstamon/Servers/Prometheus.py | 2 +- Nagstamon/Servers/Thruk.py | 4 ++-- Nagstamon/Servers/op5Monitor.py | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Nagstamon/Servers/Alertmanager/alertmanagerserver.py b/Nagstamon/Servers/Alertmanager/alertmanagerserver.py index cab61547e..eb578fc6b 100644 --- a/Nagstamon/Servers/Alertmanager/alertmanagerserver.py +++ b/Nagstamon/Servers/Alertmanager/alertmanagerserver.py @@ -213,7 +213,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(data, error, status_code) - if errors_occured is not False: + if errors_occured is not None: return errors_occured for alert in data: diff --git a/Nagstamon/Servers/Centreon/CentreonLegacy.py b/Nagstamon/Servers/Centreon/CentreonLegacy.py index 0482ff014..76ad00859 100644 --- a/Nagstamon/Servers/Centreon/CentreonLegacy.py +++ b/Nagstamon/Servers/Centreon/CentreonLegacy.py @@ -604,7 +604,7 @@ def _get_status(self): errors_occured = self.check_for_error(xmlobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # Check if the result is not empty @@ -625,7 +625,7 @@ def _get_status(self): xmlobj, error, status_code = result.result, result.error, result.status_code errors_occured = self.check_for_error(xmlobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # a second time a bad session id should raise an error @@ -690,7 +690,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(xmlobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # Check if the result is not empty @@ -710,7 +710,7 @@ def _get_status(self): xmlobj, error, status_code = result.result, result.error, result.status_code errors_occured = self.check_for_error(xmlobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # a second time a bad session id should raise an error @@ -735,7 +735,7 @@ def _get_status(self): errors_occured = self.check_for_error(xmlobj_meta, error_meta, status_code_meta) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # a second time a bad session id should raise an error diff --git a/Nagstamon/Servers/Generic.py b/Nagstamon/Servers/Generic.py index c832cf451..d160ba69e 100644 --- a/Nagstamon/Servers/Generic.py +++ b/Nagstamon/Servers/Generic.py @@ -648,7 +648,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(htobj, error, status_code) # if there are errors return them - if errors_occured is not False: + if errors_occured is not None: return(errors_occured) # put a copy of a part of htobj into table to be able to delete htobj @@ -773,7 +773,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(htobj, error, status_code) # if there are errors return them - if errors_occured is not False: + if errors_occured is not None: return(errors_occured) # too much copy.deepcopy()s here give recursion crashs @@ -1706,7 +1706,7 @@ def check_for_error(result, error, status_code) -> Optional[Result]: error=copy.deepcopy(error), status_code=copy.deepcopy(status_code)) else: - return False + return None def get_worst_status_current(self): """ diff --git a/Nagstamon/Servers/Icinga.py b/Nagstamon/Servers/Icinga.py index ccbc0a3f4..81b2a4ae3 100644 --- a/Nagstamon/Servers/Icinga.py +++ b/Nagstamon/Servers/Icinga.py @@ -167,7 +167,7 @@ def _get_status_JSON(self): # check if any error occured errors_occured = self.check_for_error(jsonraw, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) jsondict = json.loads(jsonraw) @@ -231,7 +231,7 @@ def _get_status_JSON(self): # check if any error occured errors_occured = self.check_for_error(jsonraw, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) jsondict = json.loads(jsonraw) @@ -339,7 +339,7 @@ def _get_status_HTML(self): # check if any error occured errors_occured = self.check_for_error(htobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # put a copy of a part of htobj into table to be able to delete htobj @@ -468,7 +468,7 @@ def _get_status_HTML(self): # check if any error occured errors_occured = self.check_for_error(htobj, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) table = htobj('table', {'class': 'status'})[0] diff --git a/Nagstamon/Servers/IcingaDBWeb.py b/Nagstamon/Servers/IcingaDBWeb.py index 589da4217..a98bb423d 100644 --- a/Nagstamon/Servers/IcingaDBWeb.py +++ b/Nagstamon/Servers/IcingaDBWeb.py @@ -161,7 +161,7 @@ def _get_status(self): # check if any error occured potential_error = self.check_for_error(jsonraw, error, status_code) - if potential_error: + if potential_error is not None: return potential_error # Check if the backend is running diff --git a/Nagstamon/Servers/IcingaDBWebNotifications.py b/Nagstamon/Servers/IcingaDBWebNotifications.py index 3d1c356df..41109df25 100644 --- a/Nagstamon/Servers/IcingaDBWebNotifications.py +++ b/Nagstamon/Servers/IcingaDBWebNotifications.py @@ -86,7 +86,7 @@ def _update_new_host_content(self) -> Result: # check if any error occurred potential_error = self.check_for_error(result.result, result.error, result.status_code) - if potential_error: + if potential_error is not None: return potential_error # HEALTH CHECK diff --git a/Nagstamon/Servers/Opsview.py b/Nagstamon/Servers/Opsview.py index fe47ea0ef..ea9577fec 100644 --- a/Nagstamon/Servers/Opsview.py +++ b/Nagstamon/Servers/Opsview.py @@ -244,7 +244,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(data, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return errors_occured if conf.debug_mode: diff --git a/Nagstamon/Servers/Prometheus.py b/Nagstamon/Servers/Prometheus.py index 53e8b777b..5b502dc16 100644 --- a/Nagstamon/Servers/Prometheus.py +++ b/Nagstamon/Servers/Prometheus.py @@ -155,7 +155,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(data, error, status_code) - if errors_occured is not False: + if errors_occured is not None: return(errors_occured) if conf.debug_mode: diff --git a/Nagstamon/Servers/Thruk.py b/Nagstamon/Servers/Thruk.py index 1d0b33959..209f16223 100644 --- a/Nagstamon/Servers/Thruk.py +++ b/Nagstamon/Servers/Thruk.py @@ -279,7 +279,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(jsonraw, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # in case basic auth did not work try form login cookie based login @@ -327,7 +327,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(jsonraw, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) # in case basic auth did not work try form login cookie based login diff --git a/Nagstamon/Servers/op5Monitor.py b/Nagstamon/Servers/op5Monitor.py index 80f063c6e..9d520a353 100644 --- a/Nagstamon/Servers/op5Monitor.py +++ b/Nagstamon/Servers/op5Monitor.py @@ -151,7 +151,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(data, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) if data['count']: @@ -212,7 +212,7 @@ def _get_status(self): # check if any error occured errors_occured = self.check_for_error(data, error, status_code) # if there are errors return them - if errors_occured: + if errors_occured is not None: return(errors_occured) if data['count']: