Add timeout to dashboard, show offline status if node times out for web api

This commit is contained in:
KemoNine 2020-08-22 17:49:57 -04:00
parent 9e2f369ad4
commit de8b52b899

View file

@ -50,31 +50,36 @@ def getMonit():
cf = json.loads(f.read())
for site in cf:
s = cf[site]
r = requests.get(s['url'] + xmlQuery,
auth=(s['user'], s['passwd']),
timeout=5)
try:
s = cf[site]
r = requests.get(s['url'] + xmlQuery,
auth=(s['user'], s['passwd']),
timeout=5)
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
services = allstat['service']
status = {}
server = {}
checks = OrderedDict()
services = allstat['service']
status = {}
server = {}
checks = OrderedDict()
for service in services:
name = service['name']
status[name] = int(service['status'])
checks[name] = status[name]
for service in services:
name = service['name']
status[name] = int(service['status'])
checks[name] = status[name]
sorted_checks = OrderedDict()
sorted_checks = OrderedDict(sorted(iter(checks.items()),
key=itemgetter(1), reverse=True))
count = calculate_count(sorted_checks)
server = dict(name=site, url=s['url'],
result=sorted_checks, s_rate=count)
sorted_checks = OrderedDict()
sorted_checks = OrderedDict(sorted(iter(checks.items()),
key=itemgetter(1), reverse=True))
count = calculate_count(sorted_checks)
server = dict(name=site, url=s['url'],
result=sorted_checks, s_rate=count)
output.append(server)
output.append(server)
except:
server = dict(name=site, url=s['url'],
result=OrderedDict({'online': '1'}), s_rate={'green': 0, 'red': 1})
output.append(server)
print((datetime.datetime.now()))
return(output)