From 5360ec9e8791f99eca0e3502d843efe07bf6448f Mon Sep 17 00:00:00 2001 From: saravanan palanisamy Date: Wed, 14 Aug 2019 15:01:29 +0400 Subject: [PATCH 1/2] sort the services by status code --- bin/monit-dashboard.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 2c1d6b0..02c46f5 100755 --- a/bin/monit-dashboard.py +++ b/bin/monit-dashboard.py @@ -7,6 +7,8 @@ import json import os import sys import datetime +from collections import OrderedDict +from operator import itemgetter urls = ('/', 'index', '/help', 'help' @@ -27,7 +29,7 @@ output = [] def getMonit(): output = [] server = {} - checks = {} + checks = OrderedDict() xmlQuery = "/_status?format=xml" with open('{0}/conf/servers.json'.format(os.path.expanduser('.'))) as f: @@ -42,14 +44,16 @@ def getMonit(): services = allstat['service'] status = {} - checks = {} + checks = OrderedDict() for service in services: name = service['name'] status[name] = int(service['status']) checks[service['name']] = status[name] - server = dict(name=site, url=s['url'], result=checks) + sorted_checks = OrderedDict() + sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True)) + server = dict(name=site, url=s['url'], result=sorted_checks) output.append(server) From afe4bce47bda580af5d7ec969286e10eab1bbdde Mon Sep 17 00:00:00 2001 From: saravanan palanisamy Date: Wed, 14 Aug 2019 15:10:54 +0400 Subject: [PATCH 2/2] add few corrections --- bin/monit-dashboard.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 02c46f5..31fe677 100755 --- a/bin/monit-dashboard.py +++ b/bin/monit-dashboard.py @@ -28,8 +28,6 @@ output = [] def getMonit(): output = [] - server = {} - checks = OrderedDict() xmlQuery = "/_status?format=xml" with open('{0}/conf/servers.json'.format(os.path.expanduser('.'))) as f: @@ -44,12 +42,13 @@ def getMonit(): services = allstat['service'] status = {} + server = {} checks = OrderedDict() for service in services: name = service['name'] status[name] = int(service['status']) - checks[service['name']] = status[name] + checks[name] = status[name] sorted_checks = OrderedDict() sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True))