From 6d65637676bf16269be37814f0f74a5ff9f100a0 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 19 Dec 2020 08:46:13 +0100 Subject: [PATCH] ignore services on broken hosts --- service | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/service b/service index e4f38d0..f05e99d 100755 --- a/service +++ b/service @@ -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'],