From 28da78e75f59a966a31651e06cbf1ec1be63581e Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 28 Jun 2020 11:18:06 +0200 Subject: [PATCH] sanity_check: alert when too many checks fail on a mailbox --- cron.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cron.py b/cron.py index 339e9075..926843ad 100644 --- a/cron.py +++ b/cron.py @@ -279,12 +279,23 @@ def sanity_check(): # hack to not query DNS too often sleep(1) if not email_domain_can_be_used_as_mailbox(mailbox.email): - LOG.error( + mailbox.nb_failed_checks += 1 + # alert if too much fail + if mailbox.nb_failed_checks > 10: + log_func = LOG.error + else: + log_func = LOG.warning + + log_func( "issue with mailbox %s domain. #alias %s, nb email log %s", mailbox, mailbox.nb_alias(), mailbox.nb_email_log(), ) + else: # reset nb check + mailbox.nb_failed_checks = 0 + + db.session.commit() for user in User.filter_by(activated=True).all(): if user.email.lower() != user.email: