aboutsummaryrefslogtreecommitdiff
path: root/samplejobs/BWAuthChecker.py
diff options
context:
space:
mode:
Diffstat (limited to 'samplejobs/BWAuthChecker.py')
-rwxr-xr-xsamplejobs/BWAuthChecker.py61
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)