diff options
author | Tom Ritter <tom@ritter.vg> | 2016-01-27 13:53:33 -0500 |
---|---|---|
committer | Tom Ritter <tom@ritter.vg> | 2016-01-27 13:53:33 -0500 |
commit | 7b8920521be41680be231dcd11c1be2755f6b89f (patch) | |
tree | 14d1ec31a1f483f7c251ded3381d83a8b69f90c8 /samplejobs/BWAuthChecker.py | |
parent | c24d7577d5689972a80c7f0fa0030d37e49151ed (diff) |
Add some sample jobs for the tor servers I monitor
Diffstat (limited to 'samplejobs/BWAuthChecker.py')
-rwxr-xr-x | samplejobs/BWAuthChecker.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/samplejobs/BWAuthChecker.py b/samplejobs/BWAuthChecker.py new file mode 100755 index 0000000..9116857 --- /dev/null +++ b/samplejobs/BWAuthChecker.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import os +import time +import base64 +import logging +import datetime + +import requests + +import JobBase + +class BWAuthChecker(JobBase.JobBase): + def executeEvery(self): + return JobBase.JobFrequency.HOUR + def execute(self): + body = "" + url = "https://example.com/bwauth/bwscan.V3BandwidthsFile" + try: + r = requests.get(url) + lines = r.content.split("\n") + if len(lines) < 1: + body = "Got no response from the server.\n\n" + r.content + else: + then = datetime.datetime.utcfromtimestamp(int(lines[0])) + now = datetime.datetime.utcfromtimestamp(time.time()) + if now - then > datetime.timedelta(hours=2): + body = "The bandwidth file is more than 2 hours old.\n" + body += str((now-then).seconds / 60) + " minutes old.\n" + elif len(lines) < 8800: + body = "The bandwidth file has a low number of relays: " + str(len(lines)) + "\n" + except Exception as e: + body = "Caught an exception:\n\n" + str(e) + if body: + logging.warn("tor bwauth is broken?") + logging.warn(body) + return self.sendEmail("tor bwauth is broken?", body) + else: + return True |