also process hosts

This commit is contained in:
Cyberes 2023-11-22 23:51:23 -07:00
parent b6149a7918
commit e3664a66cc
1 changed files with 42 additions and 33 deletions

View File

@ -19,7 +19,9 @@ def main(args):
current_time = time.time()
# Get all checks
response = requests.get(url + "/objects/services", auth=(args.username, args.password), verify=not args.insecure)
objects = ["hosts", "services"]
for object in objects:
response = requests.get(url + "/objects/" + object, auth=(args.username, args.password), verify=not args.insecure)
response.raise_for_status()
checks = response.json()["results"]
@ -34,12 +36,19 @@ def main(args):
if current_time - last_check_time > check_interval + check_timeout and check['attrs']['state'] != 3:
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
next_check_time = last_check_time + check_interval + check_timeout
if object == 'services':
check_filter = f'host.name=="{check["attrs"]["host_name"]}" && service.name=="{check["attrs"]["name"]}"'
elif object == 'hosts':
check_filter = f'host.name=="{check["name"]}"'
else:
raise Exception
# Set the check to unknown
data = {
"type": check['type'],
"filter": check_filter,
"exit_status": 3,
"exit_status": 3 if check['type'] == 'Service' else 1,
"plugin_output": f"<Check is overdue for {int(current_time - next_check_time)} seconds.>",
}
@ -56,7 +65,7 @@ def main(args):
}
response = requests.post(url + "/actions/reschedule-check", data=json.dumps(data), headers=headers, auth=(args.username, args.password), verify=not args.insecure)
response.raise_for_status()
logging.info(f'Failed {check["name"]} - {int(current_time - next_check_time)} seconds overdue.')
logging.info(f'Failed {check["type"].lower()} {check["name"]} - {int(current_time - next_check_time)} seconds overdue.')
time.sleep(args.interval)