filter admin email logs for disallowed hosts
This commit is contained in:
parent
66538f7335
commit
929b8bec24
2 changed files with 26 additions and 1 deletions
|
@ -11,6 +11,7 @@ import os
|
||||||
# dotenv
|
# dotenv
|
||||||
import dotenv
|
import dotenv
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from utils.log_filters import skip_suspicious_operations
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -691,11 +692,31 @@ if ENABLE_LOGGING:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handlers_dict.update(custom_handler_item)
|
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 = {
|
LOGGING = {
|
||||||
'version': 1,
|
'version': 1,
|
||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
'handlers': handlers_dict,
|
'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')
|
TEST_MANAGE_SSH_KEY_PUBKEY = env('TEST_MANAGE_SSH_KEY_PUBKEY')
|
||||||
|
|
4
utils/log_filters.py
Normal file
4
utils/log_filters.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
def skip_suspicious_operations(record):
|
||||||
|
if record.name == 'django.security.DisallowedHost':
|
||||||
|
return False
|
||||||
|
return True
|
Loading…
Reference in a new issue