sort the services by status code

This commit is contained in:
saravanan palanisamy 2019-08-14 15:01:29 +04:00
parent 7d41263f19
commit 5360ec9e87

View file

@ -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)