diff --git a/Nagstamon/Servers/IcingaDBWeb.py b/Nagstamon/Servers/IcingaDBWeb.py index 589da4217..a09441179 100644 --- a/Nagstamon/Servers/IcingaDBWeb.py +++ b/Nagstamon/Servers/IcingaDBWeb.py @@ -208,7 +208,11 @@ def _get_status(self): else: self.new_hosts[host_name].status = self.STATES_MAPPING['hosts'][int(h['state']['soft_state'])] - self.new_hosts[host_name].last_check = datetime.datetime.fromtimestamp(int(float(h['state']['last_update']))) + if h['state']['last_update'].isnumeric(): # new version of icingadb doesnt return unix timestamp + self.new_hosts[host_name].last_check = datetime.datetime.fromtimestamp(int(float(h['state']['last_update']))) + else: + self.new_hosts[host_name].last_check = datetime.datetime.fromisoformat(h['state']['last_update']) + self.new_hosts[host_name].attempt = "{}/{}".format(h['state']['check_attempt'],h['max_check_attempts']) self.new_hosts[host_name].status_information = BeautifulSoup(h['state']['output'].replace('\n', ' ').strip(), 'html.parser').text self.new_hosts[host_name].passiveonly = not int(h.get('active_checks_enabled') or '0') @@ -231,11 +235,17 @@ def _get_status(self): self.new_hosts[host_name].attempt = "HARD" # extra duration needed for calculation - if h['state']['last_state_change'] is not None and h['state']['last_state_change'] != 0: - duration = datetime.datetime.now() - datetime.datetime.fromtimestamp(int(float(h['state']['last_state_change']))) - self.new_hosts[host_name].duration = strfdelta(duration,'{days}d {hours}h {minutes}m {seconds}s') - else: - self.new_hosts[host_name].duration = 'n/a' + self.new_hosts[host_name].duration = 'n/a' + if h['state']['last_state_change'] is not None: + if h['state']['last_state_change'].isnumeric(): # new version of icingadb doesnt return unix timestamp + duration = datetime.datetime.now() - datetime.datetime.fromtimestamp(int(float(h['state']['last_state_change']))) + else: + last_state_change = datetime.datetime.fromisoformat(h['state']['last_state_change']) + duration = datetime.datetime.now().replace(tzinfo=last_state_change.tzinfo) - last_state_change + + if duration.total_seconds() > 0: + self.new_hosts[host_name].duration = strfdelta(duration,'{days}d {hours}h {minutes}m {seconds}s') + del h, host_name except: import traceback @@ -332,6 +342,7 @@ def _get_status(self): self.new_hosts[host_name].services[service_name].attempt = "HARD" # extra duration needed for calculation + self.new_hosts[host_name].services[service_name].duration = 'n/a' if s['state']['last_state_change'] is not None: if s['state']['last_update'].isnumeric(): # new version of icingadb doesnt return unix timestamp duration = datetime.datetime.now() - datetime.datetime.fromtimestamp(int(float(s['state']['last_state_change']))) @@ -341,8 +352,6 @@ def _get_status(self): if duration.total_seconds() > 0: self.new_hosts[host_name].services[service_name].duration = strfdelta(duration, '{days}d {hours}h {minutes}m {seconds}s') - else: - self.new_hosts[host_name].services[service_name].duration = 'n/a' del s, host_name, service_name except: