|
|
@@ -4,6 +4,7 @@ import datetime
|
|
|
import requests
|
|
|
import json
|
|
|
import imp
|
|
|
+import argparse
|
|
|
|
|
|
# Nagios exit codes
|
|
|
nagios_ok = 0
|
|
|
@@ -11,20 +12,27 @@ nagios_warning = 1
|
|
|
nagios_critical = 2
|
|
|
nagios_unknown = 3
|
|
|
|
|
|
-# Two arguments are required
|
|
|
-if len(sys.argv) < 3:
|
|
|
- print 'usage: %s <creds_file> <host:port> [deviceName]' % sys.argv[0]
|
|
|
- exit(nagios_unknown)
|
|
|
+import argparse
|
|
|
+parser = argparse.ArgumentParser(description='Last Crashplan backup check')
|
|
|
+parser.add_argument("-s", "--skip", type=str, help="Hosts to skip from backup check")
|
|
|
+parser.add_argument("-d", "--device", type=str, help="Specify deviceName to check (def: all)")
|
|
|
+parser.add_argument("-H", "--host", type=str, help="<host:port> e.g. crashplan.company.org:443", required=True)
|
|
|
+parser.add_argument("-f", "--filename", type=str, help="Filename that contains credentials", required=True)
|
|
|
+args = parser.parse_args()
|
|
|
|
|
|
-filename = sys.argv[1]
|
|
|
-url = 'https://' + sys.argv[2] + '/api/DeviceBackupReport?active=true&srtKey=lastConnectedDate'
|
|
|
-critical = 0
|
|
|
-single_result = 0
|
|
|
-max_backup_time = 2 # notify if backup is older than x days
|
|
|
-status = 0
|
|
|
+filename = args.filename
|
|
|
+url = 'https://' + args.host + '/api/DeviceBackupReport?active=true&srtKey=lastConnectedDate'
|
|
|
+critical = 0
|
|
|
+single_result = 0
|
|
|
+max_backup_time = 2 # notify if backup is older than x days
|
|
|
+status = 0
|
|
|
+if args.skip:
|
|
|
+ skip = args.skip.split(",")
|
|
|
+else:
|
|
|
+ skip = "wutthehelld000d!"
|
|
|
|
|
|
-if len(sys.argv) == 4:
|
|
|
- host = sys.argv[3]
|
|
|
+if args.device:
|
|
|
+ host = args.device
|
|
|
else:
|
|
|
host = 0
|
|
|
|
|
|
@@ -48,10 +56,12 @@ def format_time(entry, orig_time):
|
|
|
global time
|
|
|
time = datetime.datetime.strptime(orig_time, "%b %d, %Y %I:%M:%S %p")
|
|
|
|
|
|
-def check_all_backup():
|
|
|
+def check_all_backup(skip):
|
|
|
for entry in data["data"]:
|
|
|
device = entry["deviceName"]
|
|
|
orig_time = entry["lastCompletedBackupDate"]
|
|
|
+ if device in skip:
|
|
|
+ continue
|
|
|
if orig_time is None:
|
|
|
continue
|
|
|
format_time(entry, orig_time)
|
|
|
@@ -73,7 +83,7 @@ data = r.json()
|
|
|
critical_days = datetime.datetime.now() - datetime.timedelta(days=max_backup_time)
|
|
|
|
|
|
if host == 0:
|
|
|
- check_all_backup()
|
|
|
+ check_all_backup(skip)
|
|
|
else:
|
|
|
check_host_backup()
|
|
|
|