remove host list from top of page
This is duplicated in the services list
This commit is contained in:
parent
62e0451d5b
commit
d7910e5fd3
3 changed files with 12 additions and 86 deletions
|
@ -1,26 +0,0 @@
|
||||||
<div class="row">
|
|
||||||
<div class="col">
|
|
||||||
<div class="card text-white border-success mb-3" style="max-width: 20rem;">
|
|
||||||
<h5 class="card-header">Operational</h5>
|
|
||||||
<div class="card-body">
|
|
||||||
{hosts_operational}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<div class="card text-white border-warning mb-3" style="max-width: 20rem;">
|
|
||||||
<h5 class="card-header">Warning</h5>
|
|
||||||
<div class="card-body">
|
|
||||||
{hosts_warning}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<div class="card text-white border-danger mb-3" style="max-width: 20rem;">
|
|
||||||
<h5 class="card-header">Critical</h5>
|
|
||||||
<div class="card-body">
|
|
||||||
{hosts_critical}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
56
service.py
56
service.py
|
@ -31,7 +31,7 @@ def do_api_calls(config):
|
||||||
data['services'] = r.json()
|
data['services'] = r.json()
|
||||||
else:
|
else:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
# hosts
|
# hosts
|
||||||
request_url = "{}/v1/objects/hosts".format(config['icinga2_api']['baseurl'])
|
request_url = "{}/v1/objects/hosts".format(config['icinga2_api']['baseurl'])
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -52,9 +52,10 @@ def do_api_calls(config):
|
||||||
data['hosts'] = r.json()
|
data['hosts'] = r.json()
|
||||||
else:
|
else:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def render_text_output(data):
|
def render_text_output(data):
|
||||||
print("{:50s} {:10s}".format("host", "status"))
|
print("{:50s} {:10s}".format("host", "status"))
|
||||||
for host in data['hosts']['results']:
|
for host in data['hosts']['results']:
|
||||||
|
@ -63,47 +64,6 @@ def render_text_output(data):
|
||||||
print("{:50s} {}".format(service['name'], service['attrs']['state']))
|
print("{:50s} {}".format(service['name'], service['attrs']['state']))
|
||||||
|
|
||||||
|
|
||||||
def render_hosts(data):
|
|
||||||
hosts_operational = ''
|
|
||||||
hosts_warning = ''
|
|
||||||
hosts_critical = ''
|
|
||||||
|
|
||||||
hosts_operational_template = """
|
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
||||||
{}
|
|
||||||
<span class="badge badge-success">OK</span>
|
|
||||||
</li>
|
|
||||||
"""
|
|
||||||
hosts_warning_template = """
|
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
||||||
{}
|
|
||||||
<span class="badge badge-warning">WARNING</span>
|
|
||||||
</li>
|
|
||||||
"""
|
|
||||||
hosts_critical_template = """
|
|
||||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
||||||
{}
|
|
||||||
<span class="badge badge-danger">CRITICAL</span>
|
|
||||||
</li>
|
|
||||||
"""
|
|
||||||
|
|
||||||
for host in data['hosts']['results']:
|
|
||||||
if host['attrs']['state'] == 0:
|
|
||||||
hosts_operational = hosts_operational + hosts_operational_template.format(host['name'])
|
|
||||||
elif host['attrs']['state'] == 1:
|
|
||||||
hosts_warning = hosts_warning + hosts_critical_template.format(host['name'])
|
|
||||||
else:
|
|
||||||
hosts_critical = hosts_critical + hosts_critical_template.format(host['name'])
|
|
||||||
|
|
||||||
with open("hosts_template.html", "r") as f:
|
|
||||||
htmlTemplate = f.read()
|
|
||||||
htmlOutput = htmlTemplate.format(
|
|
||||||
hosts_operational = hosts_operational,
|
|
||||||
hosts_warning = hosts_warning,
|
|
||||||
hosts_critical = hosts_critical,
|
|
||||||
)
|
|
||||||
return htmlOutput
|
|
||||||
|
|
||||||
def render_services_per_host(host, data):
|
def render_services_per_host(host, data):
|
||||||
services_operational = ''
|
services_operational = ''
|
||||||
services_warning = ''
|
services_warning = ''
|
||||||
|
@ -126,7 +86,7 @@ def render_services_per_host(host, data):
|
||||||
services_warning = services_warning + services_template.format(service['attrs']['display_name'], 'warning', 'WARNING')
|
services_warning = services_warning + services_template.format(service['attrs']['display_name'], 'warning', 'WARNING')
|
||||||
else:
|
else:
|
||||||
services_critical = services_critical + services_template.format(service['attrs']['display_name'], 'danger', 'CRITICAL')
|
services_critical = services_critical + services_template.format(service['attrs']['display_name'], 'danger', 'CRITICAL')
|
||||||
|
|
||||||
if service['joins']['host']['state'] == 0:
|
if service['joins']['host']['state'] == 0:
|
||||||
card_header = services_hostname_template.format(host, 'success', 'UP')
|
card_header = services_hostname_template.format(host, 'success', 'UP')
|
||||||
elif service['joins']['host']['state'] == 0:
|
elif service['joins']['host']['state'] == 0:
|
||||||
|
@ -145,6 +105,7 @@ def render_services_per_host(host, data):
|
||||||
)
|
)
|
||||||
return htmlOutput
|
return htmlOutput
|
||||||
|
|
||||||
|
|
||||||
def render_service_details(data):
|
def render_service_details(data):
|
||||||
# generate list of hosts by scanning services for unique host_name
|
# generate list of hosts by scanning services for unique host_name
|
||||||
host_names = []
|
host_names = []
|
||||||
|
@ -157,12 +118,12 @@ def render_service_details(data):
|
||||||
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
|
||||||
|
|
||||||
def render_index_html(filename, host_summary, service_details):
|
|
||||||
|
def render_index_html(filename, service_details):
|
||||||
with open("template.html", "r") as f:
|
with open("template.html", "r") as f:
|
||||||
htmlTemplate = f.read()
|
htmlTemplate = f.read()
|
||||||
|
|
||||||
htmlOutput = htmlTemplate.format(
|
htmlOutput = htmlTemplate.format(
|
||||||
hosts = host_summary,
|
|
||||||
services = service_details
|
services = service_details
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -180,9 +141,8 @@ def main():
|
||||||
with open('config.conf', 'r') as configfile:
|
with open('config.conf', 'r') as configfile:
|
||||||
config.read('config.conf')
|
config.read('config.conf')
|
||||||
data = do_api_calls(config)
|
data = do_api_calls(config)
|
||||||
host_summary = render_hosts(data)
|
|
||||||
service_details = render_service_details(data)
|
service_details = render_service_details(data)
|
||||||
render_index_html(config['output']['filename'], host_summary, service_details)
|
render_index_html(config['output']['filename'], service_details)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -8,21 +8,13 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="page-header my-5" id="banner">
|
<div class="page-header my-5" id="banner">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-md-7 col-sm-6">
|
<div class="col-lg-8 col-md-7 col-sm-6">
|
||||||
<h1>Status Page</h1>
|
<h1>Status Page</h1>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="page-header">
|
|
||||||
<h2 id="typography">Hosts</h2>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{hosts}
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
|
|
Loading…
Reference in a new issue