1

I'm getting an error message sent to my admin email address:

ADMIN = ['admin.error.email.here@domain.com'] email address.

This error message occurs at a constant rate of around two per minute.

I want to stop all error messages sent to my admin email that are HTTP_HOST errors, but at the same time still receive 500 error messages. I looked at the documentation and couldn't find any help. I searched on Stack Overflow and only found changing nginx 80 port server config file to contain a header error to a 444 error, so to bypass the 500 error report. However, this didn't work.

Is there any setting.py variable for excluding certain errors? Time is of the essence - like I said, 2 damn emails per minute from some asshole that is desperate to scrape data. It's not a security risk but it is annoying and consuming my monthly email limit from my email host.

Thanks for any help.

Tagc
  • 8,736
  • 7
  • 61
  • 114

1 Answers1

0

First off I didn't test this particular sample yet, but my approach in a similar situation was to write a custom filter for your logging.

For this first write a custom filter:

import logging 

class NoAnnoyFilter(logging.Filter):
    def filter(self, record):
        status_code = getattr(record, 'status_code', None)
        return status_code != 500

And then add it to your logging config in your settings.py:

DEFAULT_LOGGING = {
    ...
    'filters': {
        'no_annoy': {
            '()': 'myproject.utils.NoAnnoyFilter',
        },
    },
    ...
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['no_annoy'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        ...
    },
}

You can see some actual samples in the Django code itself: https://github.com/django/django/blob/6709ea4ae91b906742506ac0c42a3a272991001f/django/utils/log.py

Jann
  • 1,799
  • 3
  • 21
  • 38
  • Thanks for your response. I'm sure some one else can definitely use that idea... I ended up fixing it by changing what I had in my nginx cofig file, added this: if ($host !~* ^(example.com|www.example.com)$ ) { return 444; } – quaerere veritatem Jan 11 '17 at 03:26