check_crashplan_backup.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. import requests
  3. import datetime
  4. import json
  5. import imp
  6. filename = '/root/crashplan-credentials-for-nagios.txt'
  7. # replace host with your crashplan server
  8. url = 'https://crashplan.company.com:4285/api/DeviceBackupReport?active=true&srtKey=lastConnectedDate'
  9. # Nagios exit codes
  10. nagios_ok = 0
  11. nagios_warning = 1
  12. nagios_critical = 2
  13. nagios_unknown = 3
  14. try:
  15. f = open(filename, "r")
  16. except IOError:
  17. print "Could not open credential file! Does it exist?"
  18. exit(nagios_unknown)
  19. global data
  20. creds = imp.load_source('data', '', f)
  21. f.close()
  22. r = requests.get(url, auth=(creds.user, creds.password))
  23. r.raise_for_status()
  24. data = r.json()
  25. two_days_ago = datetime.datetime.now() - datetime.timedelta(days=2)
  26. for entry in data["data"]:
  27. device = entry["deviceName"]
  28. orig_time = entry["lastCompletedBackupDate"]
  29. if orig_time is None:
  30. continue
  31. time = datetime.datetime.strptime(orig_time, "%b %d, %Y %I:%M:%S %p")
  32. if time < two_days_ago:
  33. print "CRITICAL: %s: LastCompleteBackup: %s" % (device, orig_time)
  34. critical = 1
  35. if critical == 1:
  36. exit(nagios_critical)
  37. print "OK: All backups have been completed recently"
  38. exit(nagios_ok)