add readability and some sorting
This commit is contained in:
parent
7e1c6ecdca
commit
f5b36531ca
1 changed files with 4 additions and 6 deletions
10
services.py
10
services.py
|
@ -64,11 +64,11 @@ def render_services_per_host(host, data):
|
||||||
for service in data['services']['results']:
|
for service in data['services']['results']:
|
||||||
if service['attrs']['host_name'] == host:
|
if service['attrs']['host_name'] == host:
|
||||||
if service['attrs']['state'] == 0:
|
if service['attrs']['state'] == 0:
|
||||||
services_operational = services_operational + """<p><button type="button" class="btn btn-success">{}</button></p>\n""".format(service['name'])
|
services_operational = services_operational + """<p><button type="button" class="btn btn-success">{}</button></p>\n""".format(service['attrs']['display_name'])
|
||||||
elif service['attrs']['state'] == 1:
|
elif service['attrs']['state'] == 1:
|
||||||
services_warning = services_warning + """<p><button type="button" class="btn btn-warning">{}</button></p>\n""".format(service['name'])
|
services_warning = services_warning + """<p><button type="button" class="btn btn-warning">{}</button></p>\n""".format(service['attrs']['display_name'])
|
||||||
else:
|
else:
|
||||||
services_critical = services_critical + """<p><button type="button" class="btn btn-danger">{}</button></p>\n""".format(service['name'])
|
services_critical = services_critical + """<p><button type="button" class="btn btn-danger">{}</button></p>\n""".format(service['attrs']['display_name'])
|
||||||
|
|
||||||
with open("services_template.html", "r") as f:
|
with open("services_template.html", "r") as f:
|
||||||
htmlTemplate = f.read()
|
htmlTemplate = f.read()
|
||||||
|
@ -87,10 +87,9 @@ def render_service_details(data):
|
||||||
for service in data['services']['results']:
|
for service in data['services']['results']:
|
||||||
if service['attrs']['host_name'] not in host_names:
|
if service['attrs']['host_name'] not in host_names:
|
||||||
host_names.append(service['attrs']['host_name'])
|
host_names.append(service['attrs']['host_name'])
|
||||||
print(host_names)
|
|
||||||
# render html for each host_name
|
# render html for each host_name
|
||||||
html_output = ""
|
html_output = ""
|
||||||
for host in host_names:
|
for host in sorted(host_names):
|
||||||
html_output = html_output + render_services_per_host(host, data)
|
html_output = html_output + render_services_per_host(host, data)
|
||||||
return html_output
|
return html_output
|
||||||
|
|
||||||
|
@ -119,7 +118,6 @@ def main():
|
||||||
data = do_api_calls(config)
|
data = do_api_calls(config)
|
||||||
host_summary = render_hosts(data)
|
host_summary = render_hosts(data)
|
||||||
service_details = render_service_details(data)
|
service_details = render_service_details(data)
|
||||||
print(service_details)
|
|
||||||
render_index_html(host_summary, service_details)
|
render_index_html(host_summary, service_details)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue