check borgmatic backup
This commit is contained in:
parent
97b695cffb
commit
ee9a010178
1 changed files with 30 additions and 0 deletions
30
check_borg_backup.py
Executable file
30
check_borg_backup.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/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)
|
Loading…
Reference in a new issue