From 2c5420cc9dddcdbc71b46dafaca4390fd7367fff Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 5 Sep 2024 16:18:14 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=92=84=20=E2=80=94=20Use=20a=20custom?= =?UTF-8?q?=20User-Agent=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ argos/agent.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a7402..13fdfbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +- 💄 — Use a custom User-Agent header + ## 0.4.0 Date: 2024-09-04 diff --git a/argos/agent.py b/argos/agent.py index e0a4608..73c0359 100644 --- a/argos/agent.py +++ b/argos/agent.py @@ -11,6 +11,7 @@ from typing import List import httpx from tenacity import retry, wait_random # type: ignore +from argos import VERSION from argos.checks import get_registered_check from argos.logging import logger from argos.schemas import AgentResult, SerializableException, Task @@ -47,6 +48,7 @@ class ArgosAgent: async def run(self): headers = { "Authorization": f"Bearer {self.auth}", + "User-Agent": f"Argos Panoptes {VERSION} (about: https://argos-monitoring.framasoft.org/)", } self._http_client = httpx.AsyncClient(headers=headers) logger.info("Running agent against %s", self.server) From c62bf82e0d7c0e30feeede1581cf8e2fb4ec9718 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Wed, 18 Sep 2024 11:44:40 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20=E2=80=94=20Fix=20mail=20and?= =?UTF-8?q?=20gotify=20alerting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + argos/agent.py | 3 ++- argos/server/alerting.py | 17 ++++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13fdfbc..d358f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] - 💄 — Use a custom User-Agent header +- 🐛 — Fix mail and gotify alerting ## 0.4.0 diff --git a/argos/agent.py b/argos/agent.py index 73c0359..580553d 100644 --- a/argos/agent.py +++ b/argos/agent.py @@ -48,7 +48,8 @@ class ArgosAgent: async def run(self): headers = { "Authorization": f"Bearer {self.auth}", - "User-Agent": f"Argos Panoptes {VERSION} (about: https://argos-monitoring.framasoft.org/)", + "User-Agent": f"Argos Panoptes {VERSION} " + "(about: https://argos-monitoring.framasoft.org/)", } self._http_client = httpx.AsyncClient(headers=headers) logger.info("Running agent against %s", self.server) diff --git a/argos/server/alerting.py b/argos/server/alerting.py index 64e6bc9..60384aa 100644 --- a/argos/server/alerting.py +++ b/argos/server/alerting.py @@ -1,5 +1,6 @@ import ssl import smtplib +from email.message import EmailMessage from typing import List from urllib.parse import urlparse @@ -107,10 +108,10 @@ See result on {request.url_for('get_result_view', result_id=result.id)} See results of task on {request.url_for('get_task_results_view', task_id=task.id)}#{result.id} """ - mail = f"""\ -Subject: [Argos] {icon} {urlparse(task.url).netloc}: status {severity} - -{msg}""" + mail = EmailMessage() + mail["Subject"] = f"[Argos] {icon} {urlparse(task.url).netloc}: status {severity}" + mail["From"] = config.mailfrom + mail.set_content(msg) if config.ssl: logger.debug("Mail notification: SSL") @@ -133,7 +134,7 @@ Subject: [Argos] {icon} {urlparse(task.url).netloc}: status {severity} for address in config.addresses: logger.debug("Sending mail to %s", address) logger.debug(msg) - smtp.sendmail(config.mailfrom, address, mail) + smtp.send_message(mail, to_addrs=address) def notify_with_gotify( @@ -166,14 +167,16 @@ See results of task on <{request.url_for('get_task_results_view', task_id=task.i extras = { "client::display": {"contentType": "text/markdown"}, "client::notification": { - "click": {"url": request.url_for("get_result_view", result_id=result.id)} + "click": { + "url": f"{request.url_for('get_result_view', result_id=result.id)}" + } }, } payload = {"title": subject, "message": msg, "priority": priority, "extras": extras} for url in config: - logger.debug("Sending gotify message(s) to %s", url) + logger.debug("Sending gotify message(s) to %s", url.url) for token in url.tokens: try: res = httpx.post(