create service list based on env
This commit is contained in:
parent
b136bbeb5a
commit
0bdf6d0f58
|
@ -26,12 +26,11 @@ web.config.debug = False
|
||||||
output = []
|
output = []
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
|
|
||||||
def calculate_count(data):
|
def calculate_count(data):
|
||||||
count = {}
|
count = {}
|
||||||
ls = data.values()
|
|
||||||
z, nz = 0, 0
|
z, nz = 0, 0
|
||||||
|
for _,v in data.items():
|
||||||
|
ls = v.values()
|
||||||
for v in ls:
|
for v in ls:
|
||||||
if v == 0:
|
if v == 0:
|
||||||
z += 1
|
z += 1
|
||||||
|
@ -41,6 +40,26 @@ def calculate_count(data):
|
||||||
count['red'] = nz
|
count['red'] = nz
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
def arrange_services(services):
|
||||||
|
checks = {}
|
||||||
|
for service in services:
|
||||||
|
name = service['name']
|
||||||
|
name1, _, name2 = name.partition('-')
|
||||||
|
if name2 == '':
|
||||||
|
name2 = name1
|
||||||
|
name1 = 'All'
|
||||||
|
if name1 not in list(checks.keys()):
|
||||||
|
checks[name1] = OrderedDict()
|
||||||
|
checks[name1][name2] = int(service['status'])
|
||||||
|
return checks
|
||||||
|
|
||||||
|
def sorted_checks(checks):
|
||||||
|
s_checks = {}
|
||||||
|
for k,v in checks.iteritems():
|
||||||
|
s_checks[k] = OrderedDict(
|
||||||
|
sorted(v.iteritems(),key=itemgetter(1), reverse=True)
|
||||||
|
)
|
||||||
|
return s_checks
|
||||||
|
|
||||||
def getMonit():
|
def getMonit():
|
||||||
output = []
|
output = []
|
||||||
|
@ -57,22 +76,14 @@ def getMonit():
|
||||||
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
|
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
|
||||||
|
|
||||||
services = allstat['service']
|
services = allstat['service']
|
||||||
status = {}
|
|
||||||
server = {}
|
server = {}
|
||||||
checks = OrderedDict()
|
|
||||||
|
|
||||||
for service in services:
|
checks = arrange_services(services)
|
||||||
name = service['name']
|
s_checks = sorted_checks(checks)
|
||||||
status[name] = int(service['status'])
|
count = calculate_count(s_checks)
|
||||||
checks[name] = status[name]
|
|
||||||
|
|
||||||
sorted_checks = OrderedDict()
|
|
||||||
sorted_checks = OrderedDict(sorted(checks.iteritems(),
|
|
||||||
key=itemgetter(1), reverse=True))
|
|
||||||
count = calculate_count(sorted_checks)
|
|
||||||
server = dict(name=site, url=s['url'],
|
server = dict(name=site, url=s['url'],
|
||||||
result=sorted_checks, s_rate=count)
|
result=s_checks, s_rate=count)
|
||||||
|
print(server)
|
||||||
output.append(server)
|
output.append(server)
|
||||||
print(datetime.datetime.now())
|
print(datetime.datetime.now())
|
||||||
return(output)
|
return(output)
|
||||||
|
|
Loading…
Reference in a new issue