diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 9ab2801..74f15c2 100755 --- a/bin/monit-dashboard.py +++ b/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) + 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)