diff options
author | Tom Ritter <tom@ritter.vg> | 2017-03-07 16:15:27 -0600 |
---|---|---|
committer | Tom Ritter <tom@ritter.vg> | 2017-03-07 16:21:46 -0600 |
commit | fff94ecb1da0b3490adc4b8bc2e2fa590aa8aa80 (patch) | |
tree | 7f308031a89bb4a6ec03ad361656461a24337e85 /samplejobs | |
parent | 1ec9b382955e2264bc2cab56d0b4247d33b26bbd (diff) |
Improve the Bandwidth Auth checker to checker for two more error conditions
Diffstat (limited to 'samplejobs')
-rwxr-xr-x | samplejobs/BWAuthChecker.py | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/samplejobs/BWAuthChecker.py b/samplejobs/BWAuthChecker.py index de3a86e..ee0113a 100755 --- a/samplejobs/BWAuthChecker.py +++ b/samplejobs/BWAuthChecker.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import re import time import base64 import logging @@ -17,22 +18,70 @@ class BWAuthChecker(JobBase.JobBase): return JobBase.JobFailureNotificationFrequency.EVERYTIME def execute(self): body = "" - url = "https://example.com/bwauth/bwscan.V3BandwidthsFile" + url = "https://bwauth.ritter.vg/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 + body = "Got no response for " + url + " 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=3): - body = "The bandwidth file is more than 3 hours old.\n" + if now - then > datetime.timedelta(hours=4): + body = "The bandwidth file is more than 4 hours old.\n" body += str((now-then).seconds / 60) + " minutes old.\n" - elif len(lines) < 8800: + elif len(lines) < 8300: 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) + body = "Caught an exception checking the bwandwidth file timestamp:\n\n" + str(e) + + url = "https://bwauth.ritter.vg/bwauth/AA_percent-measured.txt" + try: + r = requests.get(url) + lines = r.content.split("\n") + if len(lines) < 1: + body += "\n\nGot no response for " + url + " from the server.\n\n" + r.content + else: + i = -1 + while not lines[i].strip(): + i -= 1 + g = re.match('NOTICE\[.+\]:Measured ([0-9].+)% of all tor nodes', lines[i]) + if not g: + body += "\n\nCould not find the measured percentage at " + url + else: + percent = float(g.groups(0)[0]) + if percent < 96: + body += "\n\nMeasured percentant of all tor nodes is low: " + str(percent) + except Exception as e: + body += "\n\nCaught an exception measuring the percentage of relays measured:\n\n" + str(e) + + + url = "https://bwauth.ritter.vg/bwauth/AA_scanner_loop_times.txt" + try: + r = requests.get(url) + lines = r.content.split("\n") + if len(lines) < 1: + body += "\n\nGot no response for " + url + " from the server.\n\n" + r.content + else: + this_scanner = 0 + last_measured = None + measurement_times = {} + for l in lines: + if "Scanner" in l: + if this_scanner != 0: + measurement_times[this_scanner] = last_measured + this_scanner = int(l.replace("Scanner ", "").strip()) + elif l.strip(): + last_measured = re.match("NOTICE\[[^\s]+ ([0-9a-zA-Z: ]+)\]", l).groups(0)[0] + last_measured = datetime.datetime.strptime(last_measured, "%b %d %H:%M:%S %Y") + + for t in measurement_times: + if measurement_times[t] + datetime.timedelta(days=6) < datetime.datetime.now(): + body += "\n\nhttps://bwauth.ritter.vg/bwauth/AA_scanner_loop_times.txt\n" + body += "Scanner " + str(t) + " appears to be several days behind schedule." + except Exception as e: + body += "\n\nCaught an exception measuring the scanner loop times:\n\n" + str(e) + if body: logging.warn("tor bwauth is broken?") logging.warn(body) |