diff options
| -rwxr-xr-x | samplejobs/BWAuthChecker.py | 39 | ||||
| -rwxr-xr-x | samplejobs/MetricsChecker.py | 32 | 
2 files changed, 71 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 diff --git a/samplejobs/MetricsChecker.py b/samplejobs/MetricsChecker.py new file mode 100755 index 0000000..d46c7d3 --- /dev/null +++ b/samplejobs/MetricsChecker.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import os +import base64 +import logging +import datetime  + +import requests + +import JobBase + +class MetricsChecker(JobBase.JobBase): +    def executeEvery(self): +        return JobBase.JobFrequency.DAY_NOON +    def execute(self): +        body = "" +        ys = datetime.date.today() - datetime.timedelta(hours=24) +        url = "https://example.com/out/relay-descriptors/consensus/" + str(ys.year) + "/" + str(ys.month).zfill(2) + "/" + str(ys.day).zfill(2) + "/" +        try: +            r = requests.get(url) +            if "12-00-00-consensus" in r.content: +                pass +            else: +                body = "Could not find 12-00-00-consensus in the body:\n\n" + r.content +        except Exception as e: +            body = "Caught an exception:\n\n" + str(e) +        if body: +            logging.warn("tor metrics is broken?") +            logging.warn(body) +            return self.sendEmail("tor metrics is broken?", body) +        else: +            return True | 
