Skip to content

Commit

Permalink
Merge pull request #980 from DeadHunter/master
Browse files Browse the repository at this point in the history
fixed issue with date string in new icingadb version for host objects #962
  • Loading branch information
HenriWahl authored Oct 31, 2023
2 parents c7c53e7 + 195b742 commit d0dc7b1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Nagstamon/Servers/IcingaDBWeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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'])))
Expand All @@ -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:
Expand Down

0 comments on commit d0dc7b1

Please sign in to comment.