Instantly share code, notes, and snippets.

Embed
What would you like to do?
check_hyperbackup.py
#!/usr/bin/env python
"""
Nagios plugin to check synology hyperbackup vault server
"""
import re
import sys
import datetime
from datetime import timedelta
LOGFILE = open('/var/log/synolog/synobackup_server.log', 'r')
FILE = LOGFILE.readlines()
LOGFILE.close()
TABLEAU = []
SOURCE = sys.argv[1]
COMPLETE = "Backup complete"
# datetime - nb de jours en param
DELTA = (datetime.datetime.now() - timedelta(days=int(sys.argv[2])))
DATE = (DELTA.strftime("%Y/%m/%d %H:%M:%S"))
# split log lines in sorted array
for line in FILE:
if re.search(SOURCE, line):
lines = line.split('\t')
TABLEAU.append(lines)
TABLEAU.sort(reverse=True)
# if error exit critical
for row in TABLEAU:
if row[1] > DATE:
if re.search("err", row[0]):
print("CRITICAL - %s" % row[1]+' '+row[4])
sys.exit(2)
# if complete exit success
for row in TABLEAU:
if row[1] > DATE:
if re.search(COMPLETE, row[4]):
print("OK - %s" % row[1]+' '+row[4])
sys.exit(0)
# if another state exit critical and display last log line
print(TABLEAU[-1])
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment