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