Parcourir la source

Send mails with traceback upon error

Baptiste Jonglez il y a 10 ans
Parent
commit
d29ae4fa9c
2 fichiers modifiés avec 19 ajouts et 0 suppressions
  1. 7 0
      config.py.sample
  2. 12 0
      peerfinder.py

+ 7 - 0
config.py.sample

@@ -9,3 +9,10 @@ PEERFINDER_DN42 = "http://127.0.0.1:8888"
 # participants anymore.  This avoids a huge backlog when new participants
 # join the worker pool.  Default: 0 (no restriction)
 MAX_AGE = 10800
+
+# For getting notifications by mail when there is an error
+ADMINS = ["foo@example.com"]
+
+# SMTP configuration for emails
+SMTP_SERVER = "127.0.0.1"
+FROM_ADDRESS = "peerfinder@example.com"

+ 12 - 0
peerfinder.py

@@ -328,5 +328,17 @@ def show_results(target_uniqueid):
 
 
 if __name__ == '__main__':
+    if not app.debug:
+        import logging
+        from logging.handlers import SMTPHandler
+        smtp_server = app.config.get('SMTP_SERVER', "127.0.0.1")
+        from_address = app.config.get('FROM_ADDRESS', "peerfinder@example.com")
+        admins = app.config.get('ADMINS', [])
+        if admins:
+            mail_handler = SMTPHandler(smtp_server,
+                                       from_address,
+                                       admins, 'Peerfinder error')
+            mail_handler.setLevel(logging.ERROR)
+            app.logger.addHandler(mail_handler)
     init_db()
     manager.run()