monitoring-plugins/check_borg_backup.py

30 lines
782 B
Python
Raw Normal View History

2020-04-19 17:09:22 +02:00
#!/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)
if timedelta(hours=48) < since_last_backup:
print('CRITICAL - ' + str(since_last_backup) + ' sice last backup')
sys.exit(CRITICAL)
elif timedelta(hours=30) < since_last_backup:
print('WARNING - ' + str(since_last_backup) + ' sice last backup')
sys.exit(WARNING)
else:
print('OK - ' + str(since_last_backup) + ' sice last backup')
sys.exit(OK)