mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
nagios: Don’t crash on missing cron file.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
69a2ad02cd
commit
5050fb19f6
@@ -11,25 +11,31 @@ def nagios_from_file(results_file: str) -> Tuple[int, str]:
|
|||||||
This file is created by various nagios checking cron jobs such as
|
This file is created by various nagios checking cron jobs such as
|
||||||
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
||||||
|
|
||||||
with open(results_file) as f:
|
try:
|
||||||
data = f.read().strip()
|
with open(results_file) as f:
|
||||||
pieces = data.split('|')
|
data = f.read().strip()
|
||||||
|
except FileNotFoundError:
|
||||||
if not len(pieces) == 4:
|
|
||||||
state = 'UNKNOWN'
|
state = 'UNKNOWN'
|
||||||
ret = 3
|
ret = 3
|
||||||
data = "Results file malformed"
|
data = "Results file is missing"
|
||||||
else:
|
else:
|
||||||
timestamp = int(pieces[0])
|
pieces = data.split('|')
|
||||||
|
|
||||||
time_diff = time.time() - timestamp
|
if not len(pieces) == 4:
|
||||||
if time_diff > 60 * 2:
|
|
||||||
ret = 3
|
|
||||||
state = 'UNKNOWN'
|
state = 'UNKNOWN'
|
||||||
data = "Results file is stale"
|
ret = 3
|
||||||
|
data = "Results file malformed"
|
||||||
else:
|
else:
|
||||||
ret = int(pieces[1])
|
timestamp = int(pieces[0])
|
||||||
state = pieces[2]
|
|
||||||
data = pieces[3]
|
time_diff = time.time() - timestamp
|
||||||
|
if time_diff > 60 * 2:
|
||||||
|
ret = 3
|
||||||
|
state = 'UNKNOWN'
|
||||||
|
data = "Results file is stale"
|
||||||
|
else:
|
||||||
|
ret = int(pieces[1])
|
||||||
|
state = pieces[2]
|
||||||
|
data = pieces[3]
|
||||||
|
|
||||||
return (ret, f"{state}: {data}")
|
return (ret, f"{state}: {data}")
|
||||||
|
|||||||
Reference in New Issue
Block a user