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 c5e0374
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions devel/ansible/roles/dev/files/mirrormanager2.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
OIDC_CLIENT_SECRETS = '/home/vagrant/client_secrets.json'
OIDC_SCOPES = " ".join(['openid', 'email', 'profile', 'https://id.fedoraproject.org/scope/groups', 'https://id.fedoraproject.org/scope/agreements'])
ADMIN_GROUP = ["infra"]
SERVER_NAME = "mirrormanager.tinystage.test"
PREFERRED_URL_SCHEME = "https"
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 c5e0374

Please sign in to comment.