mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
🐛 — Fix mail and gotify alerting
This commit is contained in:
parent
2c5420cc9d
commit
c62bf82e0d
3 changed files with 13 additions and 8 deletions
|
@ -3,6 +3,7 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- 💄 — Use a custom User-Agent header
|
- 💄 — Use a custom User-Agent header
|
||||||
|
- 🐛 — Fix mail and gotify alerting
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ class ArgosAgent:
|
||||||
async def run(self):
|
async def run(self):
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {self.auth}",
|
"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)
|
self._http_client = httpx.AsyncClient(headers=headers)
|
||||||
logger.info("Running agent against %s", self.server)
|
logger.info("Running agent against %s", self.server)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import ssl
|
import ssl
|
||||||
import smtplib
|
import smtplib
|
||||||
|
from email.message import EmailMessage
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
from urllib.parse import urlparse
|
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}
|
See results of task on {request.url_for('get_task_results_view', task_id=task.id)}#{result.id}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
mail = f"""\
|
mail = EmailMessage()
|
||||||
Subject: [Argos] {icon} {urlparse(task.url).netloc}: status {severity}
|
mail["Subject"] = f"[Argos] {icon} {urlparse(task.url).netloc}: status {severity}"
|
||||||
|
mail["From"] = config.mailfrom
|
||||||
{msg}"""
|
mail.set_content(msg)
|
||||||
|
|
||||||
if config.ssl:
|
if config.ssl:
|
||||||
logger.debug("Mail notification: SSL")
|
logger.debug("Mail notification: SSL")
|
||||||
|
@ -133,7 +134,7 @@ Subject: [Argos] {icon} {urlparse(task.url).netloc}: status {severity}
|
||||||
for address in config.addresses:
|
for address in config.addresses:
|
||||||
logger.debug("Sending mail to %s", address)
|
logger.debug("Sending mail to %s", address)
|
||||||
logger.debug(msg)
|
logger.debug(msg)
|
||||||
smtp.sendmail(config.mailfrom, address, mail)
|
smtp.send_message(mail, to_addrs=address)
|
||||||
|
|
||||||
|
|
||||||
def notify_with_gotify(
|
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 = {
|
extras = {
|
||||||
"client::display": {"contentType": "text/markdown"},
|
"client::display": {"contentType": "text/markdown"},
|
||||||
"client::notification": {
|
"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}
|
payload = {"title": subject, "message": msg, "priority": priority, "extras": extras}
|
||||||
|
|
||||||
for url in config:
|
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:
|
for token in url.tokens:
|
||||||
try:
|
try:
|
||||||
res = httpx.post(
|
res = httpx.post(
|
||||||
|
|
Loading…
Reference in a new issue