2013-04-16 20:07:53 +02:00
|
|
|
import time
|
|
|
|
|
2016-11-30 21:45:02 +01:00
|
|
|
if False:
|
2018-12-17 19:52:08 +01:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-in-production-scripts
|
2016-11-30 21:45:02 +01:00
|
|
|
from typing import Tuple
|
2016-07-30 01:09:08 +02:00
|
|
|
|
2013-04-16 20:07:53 +02:00
|
|
|
def nagios_from_file(results_file):
|
2016-07-30 01:09:08 +02:00
|
|
|
# type: (str) -> Tuple[int, str]
|
2013-04-16 20:07:53 +02:00
|
|
|
"""Returns a nagios-appropriate string and return code obtained by
|
|
|
|
parsing the desired file on disk. The file on disk should be of format
|
|
|
|
|
|
|
|
%s|%s % (timestamp, nagios_string)
|
|
|
|
|
|
|
|
This file is created by various nagios checking cron jobs such as
|
|
|
|
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
|
|
|
|
2015-10-14 22:31:08 +02:00
|
|
|
data = open(results_file).read().strip()
|
2013-04-16 20:07:53 +02:00
|
|
|
pieces = data.split('|')
|
|
|
|
|
|
|
|
if not len(pieces) == 4:
|
|
|
|
state = 'UNKNOWN'
|
|
|
|
ret = 3
|
|
|
|
data = "Results file malformed"
|
|
|
|
else:
|
|
|
|
timestamp = int(pieces[0])
|
|
|
|
|
|
|
|
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, "%s: %s" % (state, data))
|