diff --git a/hosts_template.html b/hosts_template.html
deleted file mode 100644
index c780203..0000000
--- a/hosts_template.html
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
- {hosts_operational}
-
-
-
-
-
-
-
- {hosts_warning}
-
-
-
-
-
-
-
- {hosts_critical}
-
-
-
-
diff --git a/service.py b/service.py
index d195b66..b116d01 100755
--- a/service.py
+++ b/service.py
@@ -31,30 +31,10 @@ def do_api_calls(config):
data['services'] = r.json()
else:
r.raise_for_status()
-
- # hosts
- request_url = "{}/v1/objects/hosts".format(config['icinga2_api']['baseurl'])
- headers = {
- 'Accept': 'application/json',
- 'X-HTTP-Method-Override': 'GET'
- }
- requestbody = {
- "attrs": [ "name", "state" ],
- "filter": config['filters']['hosts'],
- }
- r = requests.get(request_url,
- headers=headers,
- data=json.dumps(requestbody),
- auth=(config['icinga2_api']['username'], config['icinga2_api']['password']),
- verify=False)
- if (r.status_code == 200):
- data['hosts'] = r.json()
- else:
- r.raise_for_status()
-
return data
+
def render_text_output(data):
print("{:50s} {:10s}".format("host", "status"))
for host in data['hosts']['results']:
@@ -63,47 +43,6 @@ def render_text_output(data):
print("{:50s} {}".format(service['name'], service['attrs']['state']))
-def render_hosts(data):
- hosts_operational = ''
- hosts_warning = ''
- hosts_critical = ''
-
- hosts_operational_template = """
-
- {}
- OK
-
- """
- hosts_warning_template = """
-
- {}
- WARNING
-
- """
- hosts_critical_template = """
-
- {}
- CRITICAL
-
- """
-
- 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):
services_operational = ''
services_warning = ''
@@ -126,11 +65,9 @@ def render_services_per_host(host, data):
services_warning = services_warning + services_template.format(service['attrs']['display_name'], 'warning', 'WARNING')
else:
services_critical = services_critical + services_template.format(service['attrs']['display_name'], 'danger', 'CRITICAL')
-
+
if service['joins']['host']['state'] == 0:
card_header = services_hostname_template.format(host, 'success', 'UP')
- elif service['joins']['host']['state'] == 0:
- card_header = services_hostname_template.format(host, 'warning', 'WARNING')
else:
card_header = services_hostname_template.format(host, 'danger', 'DOWN')
@@ -145,6 +82,7 @@ def render_services_per_host(host, data):
)
return htmlOutput
+
def render_service_details(data):
# generate list of hosts by scanning services for unique host_name
host_names = []
@@ -157,12 +95,12 @@ def render_service_details(data):
html_output = html_output + render_services_per_host(host, data)
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:
htmlTemplate = f.read()
htmlOutput = htmlTemplate.format(
- hosts = host_summary,
services = service_details
)
@@ -180,9 +118,8 @@ def main():
with open('config.conf', 'r') as configfile:
config.read('config.conf')
data = do_api_calls(config)
- host_summary = render_hosts(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__":
main()
diff --git a/template.html b/template.html
index 1d253df..2db2587 100644
--- a/template.html
+++ b/template.html
@@ -8,25 +8,10 @@