Skip to content

Commit

Permalink
Fix the mails sent by the reporter
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jun 5, 2024
1 parent 6063871 commit f20d543
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions mirrormanager2/crawler/reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import smtplib
import time
from datetime import datetime, timezone
from email.utils import format_datetime
from typing import TYPE_CHECKING

import mirrormanager2.lib as mmlib
Expand All @@ -21,27 +22,34 @@ def __init__(self, config, session, host):
self.host = host
self.host_failed = False

def _get_log_url(self):
# This is web-framework-dependant
from flask import url_for

from mirrormanager2.app import create_app

app = create_app()
with app.app_context():
return url_for("base.crawler_log", host_id=self.host.id, _external=True)

def send_email(self, report_str, exc):
if not self.config.get("CRAWLER_SEND_EMAIL", False):
return

SMTP_DATE_FORMAT = "%a, %d %b %Y %H:%M:%S %z"
msg = """From: {}
To: {}
Subject: {} MirrorManager crawler report
Subject: MirrorManager crawler report: {}
Date: {}
""".format(
self.config.get("EMAIL_FROM"),
self.config.get("ADMIN_EMAIL"),
self.host.name,
time.strftime(SMTP_DATE_FORMAT),
format_datetime(datetime.now(tz=timezone.utc)),
)

msg += report_str + "\n"
msg += "Log can be found at {}/{}.log\n".format(
self.config.get("crawler.logdir"), str(self.host.id)
)
msg += f"Log can be found at {self._get_log_url()}\n"
if exc is not None:
msg += f"Exception info: type {exc[0]}; value {exc[1]}\n"
msg += str(exc[2])
Expand Down

0 comments on commit f20d543

Please sign in to comment.