mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
🎨 — Split mail in subject + content
This commit is contained in:
parent
2ffea278dd
commit
ec97d98231
1 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue