From b64d7567f6ba2a8729d392237b4d996f2d76bfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bompard?= Date: Wed, 28 Sep 2016 17:00:59 +0000 Subject: [PATCH] Mailman: don't report useless exceptions in Django via email --- roles/mailman/files/django_fedora.py | 17 +++++++++++++++++ roles/mailman/tasks/main.yml | 11 +++++++++++ roles/mailman/templates/settings.py.j2 | 17 ++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 roles/mailman/files/django_fedora.py diff --git a/roles/mailman/files/django_fedora.py b/roles/mailman/files/django_fedora.py new file mode 100644 index 0000000000..0f2751964e --- /dev/null +++ b/roles/mailman/files/django_fedora.py @@ -0,0 +1,17 @@ +from django.core.exceptions import DisallowedHost +from django.http import UnreadablePostError +from pylibmc import Error as MemcachedError + +EXCLUDED = ( + DisallowedHost, + UnreadablePostError, + MemcachedError, +) + +def exclude_useless_errors(record): + if record.exc_info: + exc_type, exc_value = record.exc_info[:2] + for excluded_class in EXCLUDED: + if isinstance(exc_value, EXCLUDED): + return False + return True diff --git a/roles/mailman/tasks/main.yml b/roles/mailman/tasks/main.yml index ef69b167f7..3350238dbe 100644 --- a/roles/mailman/tasks/main.yml +++ b/roles/mailman/tasks/main.yml @@ -5,6 +5,7 @@ # # SELinux +# TODO: switch to the sefcontext module when we update Ansible to 2.2+ # - name: install semanage yum: pkg=policycoreutils-python state=present @@ -266,6 +267,16 @@ - config - mailman +- name: install the django_fedora module + copy: src=django_fedora.py + dest="{{ mailman_webui_confdir }}/django_fedora.py" + owner=root group=root mode=0644 + tags: + - config + - mailman + notify: + - reload apache + - name: install the hyperkitty urls file copy: src=urls.py dest="{{ mailman_webui_confdir }}/urls.py" diff --git a/roles/mailman/templates/settings.py.j2 b/roles/mailman/templates/settings.py.j2 index 13fda3abbd..f7043822eb 100644 --- a/roles/mailman/templates/settings.py.j2 +++ b/roles/mailman/templates/settings.py.j2 @@ -6,6 +6,8 @@ Django settings for HyperKitty + Postorius import os BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +import django_fedora + # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '{{ mailman_hyperkitty_cookie_key }}' @@ -29,7 +31,7 @@ ALLOWED_HOSTS = [ ".fedoraproject.org", "localhost", # Archiving API from Mailman "127.0.0.1", # HAProxy ping - "mailman01", # Varnish ping on STG + "{{ ansible_hostname }}", # Varnish ping ] # Mailman API credentials @@ -322,12 +324,16 @@ LOGGING = { 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' + }, + 'exclude_useless_errors': { + '()': 'django.utils.log.CallbackFilter', + 'callback': django_fedora.exclude_useless_errors, } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', - 'filters': ['require_debug_false'], + 'filters': ['require_debug_false', 'exclude_useless_errors'], 'class': 'django.utils.log.AdminEmailHandler' }, 'file':{ @@ -340,7 +346,12 @@ LOGGING = { }, 'loggers': { 'django.request': { - 'handlers': ['mail_admins', 'file'], + 'handlers': [ + 'file', + {% if env == 'prod' %} + 'mail_admins', + {% endif %} + ], 'level': 'DEBUG', 'propagate': True, },