33 lines
No EOL
930 B
Python
Executable file
33 lines
No EOL
930 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import json
|
|
import sys
|
|
from dateutil import parser
|
|
from datetime import datetime, timedelta
|
|
# from datetime import timedelta
|
|
|
|
OK = 0
|
|
WARNING = 1
|
|
CRITICAL = 2
|
|
UNKNOWN = 3
|
|
|
|
BORG_STATUS_FILE='/var/log/borgmatic-last.json'
|
|
|
|
with open(BORG_STATUS_FILE) as json_file:
|
|
borg_data = json.load(json_file)
|
|
|
|
last_backup = borg_data[0]['archives'][0]['time']
|
|
since_last_backup = datetime.now() - parser.parse(last_backup)
|
|
|
|
days, seconds = since_last_backup.days, since_last_backup.seconds
|
|
hours = days * 24 + seconds // 3600
|
|
|
|
if timedelta(hours=60) < since_last_backup:
|
|
print('CRITICAL - ' + str(hours) + ' hours sice last backup |hours=' + str(hours))
|
|
sys.exit(CRITICAL)
|
|
elif timedelta(hours=30) < since_last_backup:
|
|
print('WARNING - ' + str(hours) + ' hours sice last backup |hours=' + str(hours))
|
|
sys.exit(WARNING)
|
|
else:
|
|
print('OK - ' + str(hours) + ' hours sice last backup |hours=' + str(hours))
|
|
sys.exit(OK) |