nagios: Add script and check for checking that a timestamp within a file is within a delta of now, and then use this for alerting when websites stop building
Signed-off-by: Rick Elrod <relrod@redhat.com>
This commit is contained in:
parent
60b360e9e1
commit
0135fc1102
4 changed files with 66 additions and 0 deletions
43
roles/nagios_client/files/scripts/check_timestamp_from_file
Normal file
43
roles/nagios_client/files/scripts/check_timestamp_from_file
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Takes a path to a file and a delta. The file must simply contain an epoch
|
||||
# timestamp. It can be an integer or a float, as can the delta.
|
||||
#
|
||||
# Alerts critical if (now - timestamp contained in file) > delta.
|
||||
#
|
||||
# Rick Elrod <relrod@redhat.com>
|
||||
# MIT
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print('UNKNOWN: Pass path to file and delta as parameters')
|
||||
sys.exit(3)
|
||||
|
||||
filename = sys.argv[1]
|
||||
delta = float(sys.argv[2])
|
||||
|
||||
timestamp = None
|
||||
|
||||
try:
|
||||
with open(filename, 'r') as f:
|
||||
timestamp = float(f.read().strip())
|
||||
except Exception as e:
|
||||
print('UNKNOWN: Unable to open/read file path')
|
||||
sys.exit(3)
|
||||
|
||||
difference = round(time.time() - timestamp, 2)
|
||||
if difference > delta:
|
||||
print(
|
||||
'CRITICAL: Timestamp in file (%.2f) exceeds delta (%.2f) by %.2f seconds' % (
|
||||
timestamp,
|
||||
delta,
|
||||
difference - delta))
|
||||
sys.exit(2)
|
||||
|
||||
print('OK: Timestamp in file (%.2f) is within delta (%.2f) of now, by %.2f seconds' % (
|
||||
timestamp,
|
||||
delta,
|
||||
abs(difference - delta)))
|
||||
sys.exit(0)
|
Loading…
Add table
Add a link
Reference in a new issue