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

16
service
View file

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