ignore services on broken hosts

This commit is contained in:
Franzi 2020-12-19 08:46:13 +01:00
parent 4d8812e657
commit 6d65637676
Signed by: kunsi
GPG Key ID: 12E3D2136B818350
1 changed files with 10 additions and 6 deletions

16
service
View File

@ -36,6 +36,8 @@ def regenerate():
}
try:
broken_hosts = set()
hosts = requests.get(CONFIG["url_hosts"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=False).json()
serv = requests.get(CONFIG["url_services"], auth=(CONFIG["api_user"], CONFIG["api_password"]), verify=False).json()
@ -45,10 +47,12 @@ def regenerate():
raise KeyError('API call for services did not return any results')
for host in hosts['results']:
if host['attrs']['downtime_depth'] > 0:
continue
if host['attrs']['problem']:
broken_hosts.add(host['attrs']['display_name'])
if host['attrs']['downtime_depth'] > 0:
continue
services['services'].append({
'host': host['attrs']['display_name'],
'service': '-- HOST --',
@ -64,10 +68,10 @@ def regenerate():
})
for svc in serv['results']:
if host['attrs']['downtime_depth'] > 0:
continue
if svc['attrs']['problem']:
if svc['attrs']['downtime_depth'] > 0 or svc['attrs']['host_name'] in broken_hosts:
continue
services['services'].append({
'host': svc['attrs']['host_name'],
'service': svc['attrs']['display_name'],