Browse Source

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

master
KemoNine 1 year ago
parent
commit
de8b52b899
  1. 55
      bin/monit-dashboard.py

55
bin/monit-dashboard.py

@ -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)
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
services = allstat['service']
status = {}
server = {}
checks = OrderedDict()
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)
output.append(server)
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']))
services = allstat['service']
status = {}
server = {}
checks = OrderedDict()
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)
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)

Loading…
Cancel
Save