add readability and some sorting

This commit is contained in:
Sophie Schiller 2020-11-21 22:41:51 +01:00
parent 7e1c6ecdca
commit f5b36531ca

View file

@ -64,11 +64,11 @@ def render_services_per_host(host, data):
for service in data['services']['results']:
if service['attrs']['host_name'] == host:
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:
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:
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:
htmlTemplate = f.read()
@ -87,10 +87,9 @@ def render_service_details(data):
for service in data['services']['results']:
if service['attrs']['host_name'] not in host_names:
host_names.append(service['attrs']['host_name'])
print(host_names)
# render html for each host_name
html_output = ""
for host in host_names:
for host in sorted(host_names):
html_output = html_output + render_services_per_host(host, data)
return html_output
@ -119,7 +118,6 @@ def main():
data = do_api_calls(config)
host_summary = render_hosts(data)
service_details = render_service_details(data)
print(service_details)
render_index_html(host_summary, service_details)
if __name__ == "__main__":