Files
zulip/puppet/zulip_internal/files/nagios_plugins/check_postgres_backup
Zev Benjamin c4e1d9f02a puppet: check_postgres_backup: Connect to the 'postgres' database
This allows the utility to run on trac.zulip.net, which doesn't have a 'zulip'
database.

(imported from commit c8eabb89e5e161191d6f2c92ca2b1428b17a9aa0)
2014-01-22 12:07:57 -05:00

33 lines
953 B
Python
Executable File

#!/usr/bin/python
import dateutil.parser
import pytz
import subprocess
from datetime import datetime, timedelta
states = {
"OK": 0,
"WARNING": 1,
"CRITICAL": 2,
"UNKNOWN": 3
}
def report(state, msg):
print "%s: %s" % (state, msg)
exit(states[state])
if subprocess.check_output(['psql', 'postgres', '-t', '-c',
'SELECT pg_is_in_recovery()']).strip() != 'f':
report('OK', 'this is not the primary')
try:
with open('/var/lib/nagios_state/last_postgres_backup', 'r') as f:
last_backup = dateutil.parser.parse(f.read())
except IOError:
report('UNKNOWN', 'could not determine completion time of last Postgres backup')
if datetime.now(tz=pytz.utc) - last_backup > timedelta(hours=25):
report('CRITICAL', 'last Postgres backup completed more than 25 hours ago: %s' % (last_backup,))
report('OK', 'last Postgres backup completed less than 25 hours ago: %s' % (last_backup,))