filter admin email logs for disallowed hosts

This commit is contained in:
aatish 2018-11-28 20:47:57 +05:45
parent 66538f7335
commit 929b8bec24
2 changed files with 26 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import os
# dotenv
import dotenv
from django.utils.translation import ugettext_lazy as _
from utils.log_filters import skip_suspicious_operations
logger = logging.getLogger(__name__)
@ -691,11 +692,31 @@ if ENABLE_LOGGING:
}
}
handlers_dict.update(custom_handler_item)
# Skip emails for Disallowed Hosts errors
# https://redmine.ungleich.ch/issues/6060
skip_suspicious_operations_handler = {
'mail_admins': {
'level': 'ERROR',
'filters': ['skip_suspicious_operations'],
'include_html' : True,
}
}
handlers_dict.update(skip_suspicious_operations_handler)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': handlers_dict,
'loggers': loggers_dict
'loggers': loggers_dict,
'filters': {
'skip_suspicious_operations': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_suspicious_operations,
}
}
}
TEST_MANAGE_SSH_KEY_PUBKEY = env('TEST_MANAGE_SSH_KEY_PUBKEY')

4
utils/log_filters.py Normal file
View file

@ -0,0 +1,4 @@
def skip_suspicious_operations(record):
if record.name == 'django.security.DisallowedHost':
return False
return True