2021-01-01 12:59:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from os.path import getmtime, isfile
|
|
|
|
from sys import exit
|
|
|
|
from time import time
|
|
|
|
|
|
|
|
statusfile = '/var/tmp/backup.monitoring'
|
|
|
|
if not isfile(statusfile):
|
|
|
|
print('Status file not found')
|
|
|
|
exit(3)
|
|
|
|
|
|
|
|
mtime = getmtime(statusfile)
|
|
|
|
now = time()
|
|
|
|
|
|
|
|
if now-mtime > 60*60*24*2:
|
|
|
|
print('Status file is older than 2 days!')
|
|
|
|
exit(3)
|
|
|
|
|
|
|
|
with open(statusfile, 'r') as f:
|
2021-08-01 05:57:22 +00:00
|
|
|
status = f.read().splitlines()
|
2021-01-01 12:59:42 +00:00
|
|
|
|
2021-08-01 05:57:22 +00:00
|
|
|
exitcode = status[0].strip()
|
|
|
|
|
|
|
|
if exitcode == 'ok':
|
2021-01-01 12:59:42 +00:00
|
|
|
print('OK')
|
|
|
|
exit(0)
|
2021-08-01 05:57:22 +00:00
|
|
|
elif exitcode == 'rsync_error':
|
|
|
|
print('rsync produced some errors, exit codes were:')
|
|
|
|
for line in status[1:]:
|
|
|
|
print(line)
|
2021-01-01 12:59:42 +00:00
|
|
|
exit(2)
|
2021-08-01 05:57:22 +00:00
|
|
|
elif exitcode == 'hook':
|
2021-02-07 19:47:22 +00:00
|
|
|
print('run-parts /etc/backup-pre-hook.d failed with exit code {}'.format(status[1]))
|
|
|
|
exit(2)
|
2021-08-01 05:57:22 +00:00
|
|
|
elif exitcode == 'abort_no_key':
|
2021-02-07 19:47:22 +00:00
|
|
|
print('no ssh key found in /etc/backup.priv!')
|
|
|
|
exit(1)
|
2021-01-01 12:59:42 +00:00
|
|
|
else:
|
|
|
|
# garbage in file
|
|
|
|
print(' '.join(status))
|
|
|
|
exit(3)
|