From ec97d982311e9a7872871e0e3ebfb62727df34af Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 28 Nov 2023 15:13:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E2=80=94=20Split=20mail=20in=20?= =?UTF-8?q?subject=20+=20content?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- argos/server/alerting.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/argos/server/alerting.py b/argos/server/alerting.py index ed9c106..e239885 100644 --- a/argos/server/alerting.py +++ b/argos/server/alerting.py @@ -15,20 +15,24 @@ def handle_alert(config: Config, result, task, severity): logger.error("Alerting stub: %s", msg) if config.general.mail is not None: - logger.debug('Notify of failure by mail') + logger.debug('Will send mail notification') + subject = f"[Argos] {urlparse(task.url).netloc}: status {severity}" msg = f"""\ -Subject: Argos {urlparse(task.url).netloc} status {severity} - URL: {task.url} Check: {task.check} Status: {severity} Time: {result.submitted_at} """ - notify_by_mail(msg, config.general.mail) + notify_by_mail(subject, msg, config.general.mail) -def notify_by_mail(msg: str, config: Mail) -> None: +def notify_by_mail(subject: str, msg: str, config: Mail) -> None: + mail = f"""\ +Subject: {subject} + +{msg}""" + if config.ssl: logger.debug('Mail notification: SSL') context = ssl.create_default_context() @@ -51,6 +55,6 @@ def notify_by_mail(msg: str, config: Mail) -> None: for address in config.addresses: logger.debug('Sending mail to %s', address) logger.debug(msg) - smtp.sendmail(config.mailfrom, address, msg) + smtp.sendmail(config.mailfrom, address, mail) return None