monitoring for pve-zsync backups. Simple one for now

This commit is contained in:
mdivecky 2020-06-08 10:52:29 +02:00
parent 44b47d3108
commit 4c605f15c3

49
check_pve_zsync.py Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/python3
import json
import sys
from dateutil import parser
from datetime import datetime, timedelta
from pprint import pprint
# from datetime import timedelta
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
ZSYNC_STATUS_FILE='/var/lib/pve-zsync/sync_state'
with open(ZSYNC_STATUS_FILE) as json_file:
zsync_data = json.load(json_file)
backup_state = []
failed = False
for vm in zsync_data:
for backup_name in zsync_data[vm]:
state = zsync_data[vm][backup_name]['state']
backup_state.append([vm,backup_name, state])
if state == 'ok' or state == 'syncing' or state == 'waiting':
pass
else:
failed = True
# result = []
# for backup in backup_state:
# backup_vm = backup[0]
# backup_name = backup[1]
# backup_status = backup[2]
# if backup_status == 'ok' or backup_status == 'syncing' or backup_status == 'waiting':
# pass
# else:
# print(backup_vm + ' is fucked')
if failed:
print('Backup in failed state\n')
pprint(backup_state)
sys.exit(CRITICAL)
else:
print('All backups OK')
sys.exit(OK)