add some config options

This commit is contained in:
Sophie Schiller 2021-01-02 14:02:14 +01:00
parent b901cfa034
commit b74c8b04be
2 changed files with 13 additions and 6 deletions

View file

@ -8,4 +8,11 @@ This script requires an ini-style config file named `config.conf` for icinga bas
baseurl = https://example.org:5665
username = root
password = foobar
[filters]
services = "checks_with_sms" in service.groups
hosts = "checks_with_sms" in host.groups
[output]
filename = index.html
```

View file

@ -20,7 +20,7 @@ def do_api_calls(config):
requestbody = {
"attrs": [ "name", "state", "last_check_result", "host_name", "display_name" ],
"joins": [ "host.name", "host.state", "host.last_check_result" ],
"filter": "\"checks_with_sms\" in service.groups",
"filter": config['filters']['services'],
}
r = requests.get(request_url,
headers=headers,
@ -32,7 +32,7 @@ def do_api_calls(config):
data['services'] = r.json()
else:
r.raise_for_status()
print(json.dumps(data['services']))
# hosts
request_url = "{}/v1/objects/hosts".format(config['icinga2_api']['baseurl'])
headers = {
@ -41,7 +41,7 @@ def do_api_calls(config):
}
requestbody = {
"attrs": [ "name", "state" ],
"filter": "\"checks_with_sms\" in host.groups",
"filter": config['filters']['hosts'],
}
r = requests.get(request_url,
headers=headers,
@ -158,7 +158,7 @@ def render_service_details(data):
html_output = html_output + render_services_per_host(host, data)
return html_output
def render_index_html(host_summary, service_details):
def render_index_html(filename, host_summary, service_details):
with open("template.html", "r") as f:
htmlTemplate = f.read()
@ -167,7 +167,7 @@ def render_index_html(host_summary, service_details):
services = service_details
)
with open("index.html", "w") as f:
with open(filename, "w") as f:
f.write(htmlOutput)
@ -183,7 +183,7 @@ def main():
data = do_api_calls(config)
host_summary = render_hosts(data)
service_details = render_service_details(data)
render_index_html(host_summary, service_details)
render_index_html(config['output']['filename'], host_summary, service_details)
if __name__ == "__main__":
main()