diff options
author | Tom Ritter <tom@ritter.vg> | 2020-09-08 13:35:45 -0400 |
---|---|---|
committer | Tom Ritter <tom@ritter.vg> | 2020-09-08 13:35:45 -0400 |
commit | 9e24dfeaabd1c4daddb96c9c143f60cfa3374bf2 (patch) | |
tree | 68fcad74f1ff25df8d10251b9a278523b8cedf06 | |
parent | 625f942d60c2f524f389f945a4e4743e57b9393e (diff) |
Better error logging
-rwxr-xr-x | jobs/JobBase.py | 29 | ||||
-rwxr-xr-x | jobs/__init__.py | 5 | ||||
-rwxr-xr-x | samplejobs/BWAuthChecker.py | 5 |
3 files changed, 23 insertions, 16 deletions
diff --git a/jobs/JobBase.py b/jobs/JobBase.py index 7f8fbc9..ac0b793 100755 --- a/jobs/JobBase.py +++ b/jobs/JobBase.py @@ -148,19 +148,21 @@ def sendEmail(config, subject, body, to=""): logging.info("Not sending email with subject '" + subject + '" but pretending we did.\n' + body) return True - FROM = config.get('email', 'user') - PASS = config.get('email', 'pass') - if not to: - to = config.get('general', 'alertcontact') - - # Prepare actual message - # Avoid gmail threading - subject = "[" + config.get('general', 'servername') + "] " + subject + " " - if config.getboolean('email', 'bustgmailthreading'): - subject += str(random.random()) - message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" \ - % (FROM, ", ".join(to), subject, body) try: + FROM = config.get('email', 'user') + PASS = config.get('email', 'pass') + + if not to: + to = config.get('general', 'alertcontact') + + # Prepare actual message + # Avoid gmail threading + subject = "[" + config.get('general', 'servername') + "] " + subject + " " + if config.getboolean('email', 'bustgmailthreading'): + subject += str(random.random()) + message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" \ + % (FROM, ", ".join(to), subject, body) + server = smtplib.SMTP(config.get('email', 'smtpserver'), config.get('email', 'smtpport')) server.ehlo() server.starttls() @@ -169,5 +171,6 @@ def sendEmail(config, subject, body, to=""): server.close() return True except Exception as e: - logging.critical("Caught an exception trying to send an email:" + str(e)) + logging.critical("Caught an exception trying to send an email:" + repr(e)) + logging.critical(logging.traceback.format_exc()) return False diff --git a/jobs/__init__.py b/jobs/__init__.py index b4b4f48..efce333 100755 --- a/jobs/__init__.py +++ b/jobs/__init__.py @@ -78,11 +78,12 @@ class JobFinder(object): module = load_module('jobs.' + full_name, file, pathname, description) except Exception as e: - logging.critical('Import Error on ' + module_name + ': ' + str(e)) + logging.critical('Import Error on ' + module_name + ': ' + repr(e)) + logging.critical(logging.traceback.format_exc()) jobs.JobBase.sendEmail(self.config, 'Import Error on ' + module_name, str(e)) continue job_modules.append(module) return job_modules def get_jobs(self): - return self._jobs
\ No newline at end of file + return self._jobs diff --git a/samplejobs/BWAuthChecker.py b/samplejobs/BWAuthChecker.py index b79ffc2..dca17b5 100755 --- a/samplejobs/BWAuthChecker.py +++ b/samplejobs/BWAuthChecker.py @@ -36,7 +36,8 @@ class BWAuthChecker(JobBase.JobBase): 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 checking the bwandwidth file timestamp:\n\n" + str(e) + body = "Caught an exception checking the bwandwidth file timestamp:\n\n" + repr(e) + body += "\n" + logging.traceback.format_exc() url = "https://bwauth.ritter.vg/bwauth/AA_percent-measured.txt" try: @@ -57,6 +58,7 @@ class BWAuthChecker(JobBase.JobBase): 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) + body += "\n" + logging.traceback.format_exc() url = "https://bwauth.ritter.vg/bwauth/AA_scanner_loop_times.txt" @@ -85,6 +87,7 @@ class BWAuthChecker(JobBase.JobBase): 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) + body += "\n" + logging.traceback.format_exc() if body: logging.warn("tor bwauth is broken?") |