Skip to content

Commit

Permalink
fix: last_check timestamp quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Ivanov committed Oct 25, 2024
1 parent f5a43c0 commit 29e0d9f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Nagstamon/Servers/IcingaDBWeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ def _get_status(self):
self.new_hosts[host_name].status = self.STATES_MAPPING['hosts'][int(h['state']['soft_state'])]

if h['state']['last_update'].replace(".", "").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'])))
#self.new_hosts[host_name].last_check = datetime.datetime.fromtimestamp(int(float(h['state']['last_update'])))
utc_time = datetime.datetime.fromtimestamp(int(float(h['state']['last_update'])), tz=timezone.utc)
else:
self.new_hosts[host_name].last_check = datetime.datetime.fromisoformat(h['state']['last_update'])
#self.new_hosts[host_name].last_check = datetime.datetime.fromisoformat(h['state']['last_update'])
utc_time = datetime.datetime.fromisoformat(h['state']['last_update'])

local_time = utc_time.astimezone()
self.new_hosts[host_name].last_check = local_time.strftime("%Y-%m-%d %H:%M:%S") # format without microseconds and tz

self.new_hosts[host_name].attempt = "{}/{}".format(h['state']['check_attempt'],h['max_check_attempts'])
self.new_hosts[host_name].status_information = BeautifulSoup(str(h['state']['output']).replace('\n', ' ').strip(), 'html.parser').text
Expand Down Expand Up @@ -313,9 +318,14 @@ def _get_status(self):
self.new_hosts[host_name].services[service_name].status = self.STATES_MAPPING['services'][int(s['state']['soft_state'])]

if s['state']['last_update'].replace(".", "").isnumeric(): # new version of icingadb doesnt return unix timestamp
self.new_hosts[host_name].services[service_name].last_check = datetime.datetime.fromtimestamp(int(float(s['state']['last_update'])))
#self.new_hosts[host_name].services[service_name].last_check = datetime.datetime.fromtimestamp(int(float(s['state']['last_update'])))
utc_time = datetime.datetime.fromtimestamp(int(float(s['state']['last_update'])), tz=timezone.utc)
else:
self.new_hosts[host_name].services[service_name].last_check = datetime.datetime.fromisoformat(s['state']['last_update'])
#self.new_hosts[host_name].services[service_name].last_check = datetime.datetime.fromisoformat(s['state']['last_update'])
utc_time = datetime.datetime.fromisoformat(s['state']['last_update'])

local_time = utc_time.astimezone()
self.new_hosts[host_name].services[service_name].last_check = local_time.strftime("%Y-%m-%d %H:%M:%S") # format without microseconds and tz

self.new_hosts[host_name].services[service_name].attempt = "{}/{}".format(s['state']['check_attempt'],s['max_check_attempts'])
self.new_hosts[host_name].services[service_name].status_information = BeautifulSoup(str(s['state']['output']).replace('\n', ' ').strip(), 'html.parser').text
Expand Down

0 comments on commit 29e0d9f

Please sign in to comment.