also process hosts
This commit is contained in:
parent
b6149a7918
commit
e3664a66cc
|
@ -19,7 +19,9 @@ def main(args):
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
|
|
||||||
# Get all checks
|
# 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()
|
response.raise_for_status()
|
||||||
|
|
||||||
checks = response.json()["results"]
|
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:
|
if current_time - last_check_time > check_interval + check_timeout and check['attrs']['state'] != 3:
|
||||||
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
|
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
|
||||||
next_check_time = last_check_time + check_interval + check_timeout
|
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"]}"'
|
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
|
# Set the check to unknown
|
||||||
data = {
|
data = {
|
||||||
"type": check['type'],
|
"type": check['type'],
|
||||||
"filter": check_filter,
|
"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.>",
|
"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 = 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()
|
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)
|
time.sleep(args.interval)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue