Browse Source

HUE-737 [desktop] Email admins listed in hue.ini automatically if there's a server error.

- Only if debug mode is turned off.
abec 13 years ago
parent
commit
4fadd7944a

+ 13 - 0
desktop/conf.dist/hue.ini

@@ -33,6 +33,12 @@
   # Turn off backtrace for server error
   http_500_debug_mode=0
 
+  # Server email for internal error messages
+  ## django_server_email='hue@localhost.localdomain'
+
+  # Email backend
+  ## django_email_backend=django.core.mail.backends.smtp.EmailBackend
+
   # Set to true to use CherryPy as the webserver, set to false
   # to use Spawning as the webserver. Defaults to Spawning if
   # key is not specified.
@@ -58,6 +64,13 @@
   # Default encoding for site data
   ## default_site_encoding=utf-8
 
+  # Administrators
+  # ----------------
+  [[django_admins]]
+    ## [[[admin1]]]
+    ## name=john
+    ## email=john@doe.com
+
   # UI customizations
   # -------------------
   [[custom]]

+ 13 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -42,6 +42,12 @@
   # Turn off backtrace for server error
   http_500_debug_mode=1
 
+  # Server email for internal error messages
+  ## django_server_email='hue@localhost.localdomain'
+
+  # Email backend
+  ## django_email_backend=django.core.mail.backends.smtp.EmailBackend
+
   # Set to true to use CherryPy as the webserver, set to false
   # to use Spawning as the webserver. Defaults to Spawning if
   # key is not specified.
@@ -67,6 +73,13 @@
   # Default encoding for site data
   ## default_site_encoding=utf-8
 
+  # Administrators
+  # ----------------
+  [[django_admins]]
+    ## [[[admin1]]]
+    ## name=john
+    ## email=john@doe.com
+
   # UI customizations
   # -------------------
   [[custom]]

+ 25 - 0
desktop/core/src/desktop/conf.py

@@ -369,6 +369,18 @@ DATABASE_LOGGING = Config(
   type=coerce_bool,
   default=False)
 
+DJANGO_ADMINS = UnspecifiedConfigSection(
+  key="django_admins",
+  help=_("Administrators that should receive error emails."),
+  each=ConfigSection(
+    members=dict(
+      NAME=Config("name",
+                  required=True,
+                  help=_("The full name of the admin.")),
+      EMAIL=Config("email",
+                   required=True,
+                   help=_("The email address of the admin.")))))
+
 DJANGO_DEBUG_MODE = Config(
   key="django_debug_mode",
   help=_("Enable or disable Django debug mode."),
@@ -385,6 +397,19 @@ HTTP_500_DEBUG_MODE = Config(
   default=True
 )
 
+DJANGO_SERVER_EMAIL = Config(
+  key='django_server_email',
+  help=_('Email address that internal error messages should send as.'),
+  default='hue@localhost.localdomain'
+)
+
+DJANGO_EMAIL_BACKEND = Config(
+  key="django_email_backend",
+  help=_("The Email backend to use."),
+  type=str,
+  default="django.core.mail.backends.smtp.EmailBackend"
+)
+
 
 def config_validator():
   """

+ 16 - 5
desktop/core/src/desktop/settings.py

@@ -62,10 +62,6 @@ desktop.log.fancy_logging()
 ############################################################
 # Part 2: Generic Configuration
 ############################################################
-ADMINS = (
-    ('Hue Administrator', 'admin@localhost')
-)
-MANAGERS = ADMINS
 
 # Language code for this installation. All choices can be found here:
 # http://www.i18nguy.com/unicode/language-identifiers.html
@@ -199,8 +195,23 @@ TEMPLATE_DEBUG = DEBUG
 # Part 4a: Django configuration that requires bound Desktop
 # configs.
 ############################################################
-# Configure database
 
+# Configure hue admins
+ADMINS = []
+for admin in desktop.conf.DJANGO_ADMINS.get():
+  admin_conf = desktop.conf.DJANGO_ADMINS[admin]
+  if 'name' in admin_conf.bind_to and 'email' in admin_conf.bind_to:
+    ADMINS.append(((admin_conf.NAME.get(), admin_conf.EMAIL.get())))
+ADMINS = tuple(ADMINS)
+MANAGERS = ADMINS
+
+# Server Email Address
+SERVER_EMAIL = desktop.conf.DJANGO_SERVER_EMAIL.get()
+
+# Email backend
+EMAIL_BACKEND = desktop.conf.DJANGO_EMAIL_BACKEND.get()
+
+# Configure database
 if os.getenv('DESKTOP_DB_CONFIG'):
   conn_string = os.getenv('DESKTOP_DB_CONFIG')
   logging.debug("DESKTOP_DB_CONFIG SET: %s" % (conn_string))

+ 1 - 1
desktop/core/src/desktop/templates/500.mako

@@ -21,7 +21,7 @@ ${commonheader(_('Error'), "", user)}
 
   <div class="container-fluid">
     <h1>${_('Server Error (500)')}</h1>
-    <p>${_("Sorry, there's been an error. Please contact your site administrators. Thanks for your patience.")}</p>
+    <p>${_("Sorry, there's been an error. An email was sent to your administrators. Thank you for your patience.")}</p>
   </div>
 
 ${commonfooter(messages)}