mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 12:41:29 +02:00
refactor
This commit is contained in:
parent
85fb859dcb
commit
f548e74e77
68
cron.py
68
cron.py
@ -709,44 +709,46 @@ def check_custom_domain():
|
|||||||
LOG.d("Check verified domain for DNS issues")
|
LOG.d("Check verified domain for DNS issues")
|
||||||
|
|
||||||
for custom_domain in CustomDomain.filter_by(verified=True): # type: CustomDomain
|
for custom_domain in CustomDomain.filter_by(verified=True): # type: CustomDomain
|
||||||
mx_domains = get_mx_domains(custom_domain.domain)
|
check_single_custom_domain(custom_domain)
|
||||||
|
|
||||||
if not is_mx_equivalent(mx_domains, EMAIL_SERVERS_WITH_PRIORITY):
|
|
||||||
user = custom_domain.user
|
def check_single_custom_domain(custom_domain):
|
||||||
LOG.w(
|
mx_domains = get_mx_domains(custom_domain.domain)
|
||||||
"The MX record is not correctly set for %s %s %s",
|
if not is_mx_equivalent(mx_domains, EMAIL_SERVERS_WITH_PRIORITY):
|
||||||
custom_domain,
|
user = custom_domain.user
|
||||||
|
LOG.w(
|
||||||
|
"The MX record is not correctly set for %s %s %s",
|
||||||
|
custom_domain,
|
||||||
|
user,
|
||||||
|
mx_domains,
|
||||||
|
)
|
||||||
|
|
||||||
|
custom_domain.nb_failed_checks += 1
|
||||||
|
|
||||||
|
# send alert if fail for 5 consecutive days
|
||||||
|
if custom_domain.nb_failed_checks > 5:
|
||||||
|
domain_dns_url = f"{URL}/dashboard/domains/{custom_domain.id}/dns"
|
||||||
|
LOG.w("Alert domain MX check fails %s about %s", user, custom_domain)
|
||||||
|
send_email_with_rate_control(
|
||||||
user,
|
user,
|
||||||
mx_domains,
|
AlERT_WRONG_MX_RECORD_CUSTOM_DOMAIN,
|
||||||
|
user.email,
|
||||||
|
f"Please update {custom_domain.domain} DNS on SimpleLogin",
|
||||||
|
render(
|
||||||
|
"transactional/custom-domain-dns-issue.txt.jinja2",
|
||||||
|
custom_domain=custom_domain,
|
||||||
|
domain_dns_url=domain_dns_url,
|
||||||
|
),
|
||||||
|
max_nb_alert=1,
|
||||||
|
nb_day=30,
|
||||||
|
retries=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
custom_domain.nb_failed_checks += 1
|
|
||||||
|
|
||||||
# send alert if fail for 5 consecutive days
|
|
||||||
if custom_domain.nb_failed_checks > 5:
|
|
||||||
domain_dns_url = f"{URL}/dashboard/domains/{custom_domain.id}/dns"
|
|
||||||
LOG.w("Alert domain MX check fails %s about %s", user, custom_domain)
|
|
||||||
send_email_with_rate_control(
|
|
||||||
user,
|
|
||||||
AlERT_WRONG_MX_RECORD_CUSTOM_DOMAIN,
|
|
||||||
user.email,
|
|
||||||
f"Please update {custom_domain.domain} DNS on SimpleLogin",
|
|
||||||
render(
|
|
||||||
"transactional/custom-domain-dns-issue.txt.jinja2",
|
|
||||||
custom_domain=custom_domain,
|
|
||||||
domain_dns_url=domain_dns_url,
|
|
||||||
),
|
|
||||||
max_nb_alert=1,
|
|
||||||
nb_day=30,
|
|
||||||
retries=3,
|
|
||||||
)
|
|
||||||
# reset checks
|
|
||||||
custom_domain.nb_failed_checks = 0
|
|
||||||
else:
|
|
||||||
# reset checks
|
# reset checks
|
||||||
custom_domain.nb_failed_checks = 0
|
custom_domain.nb_failed_checks = 0
|
||||||
|
else:
|
||||||
Session.commit()
|
# reset checks
|
||||||
|
custom_domain.nb_failed_checks = 0
|
||||||
|
Session.commit()
|
||||||
|
|
||||||
|
|
||||||
def delete_old_monitoring():
|
def delete_old_monitoring():
|
||||||
|
Loading…
Reference in New Issue
Block a user