mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
💄 — Add previous status in notifications
This commit is contained in:
parent
9ed58220f4
commit
a4163b5e25
3 changed files with 18 additions and 7 deletions
|
@ -441,7 +441,9 @@ disable=raw-checker-failed,
|
||||||
singleton-comparison,
|
singleton-comparison,
|
||||||
missing-module-docstring,
|
missing-module-docstring,
|
||||||
missing-class-docstring,
|
missing-class-docstring,
|
||||||
missing-function-docstring
|
missing-function-docstring,
|
||||||
|
too-many-arguments,
|
||||||
|
too-many-locals,
|
||||||
|
|
||||||
# Enable the message, report, category or checker with the given id(s). You can
|
# Enable the message, report, category or checker with the given id(s). You can
|
||||||
# either give multiple identifier separated by comma (,) or put this option
|
# either give multiple identifier separated by comma (,) or put this option
|
||||||
|
|
|
@ -13,7 +13,7 @@ from argos.schemas.config import Config, Mail, GotifyUrl
|
||||||
# XXX Implement mail alerts https://framagit.org/framasoft/framaspace/argos/-/issues/15
|
# XXX Implement mail alerts https://framagit.org/framasoft/framaspace/argos/-/issues/15
|
||||||
# XXX Implement gotify alerts https://framagit.org/framasoft/framaspace/argos/-/issues/16
|
# XXX Implement gotify alerts https://framagit.org/framasoft/framaspace/argos/-/issues/16
|
||||||
|
|
||||||
def handle_alert(config: Config, result, task, severity, request):
|
def handle_alert(config: Config, result, task, severity, old_severity, request):
|
||||||
"""Dispatch alert through configured alert channels"""
|
"""Dispatch alert through configured alert channels"""
|
||||||
|
|
||||||
if 'local' in getattr(config.general.alerts, severity):
|
if 'local' in getattr(config.general.alerts, severity):
|
||||||
|
@ -24,14 +24,14 @@ def handle_alert(config: Config, result, task, severity, request):
|
||||||
|
|
||||||
if config.general.mail is not None and \
|
if config.general.mail is not None and \
|
||||||
'mail' in getattr(config.general.alerts, severity):
|
'mail' in getattr(config.general.alerts, severity):
|
||||||
notify_by_mail(result, task, severity, config.general.mail, request)
|
notify_by_mail(result, task, severity, old_severity, config.general.mail, request)
|
||||||
|
|
||||||
if config.general.gotify is not None and \
|
if config.general.gotify is not None and \
|
||||||
'gotify' in getattr(config.general.alerts, severity):
|
'gotify' in getattr(config.general.alerts, severity):
|
||||||
notify_with_gotify(result, task, severity, config.general.gotify, request)
|
notify_with_gotify(result, task, severity, old_severity, config.general.gotify, request)
|
||||||
|
|
||||||
|
|
||||||
def notify_by_mail(result, task, severity, config: Mail, request) -> None:
|
def notify_by_mail(result, task, severity: str, old_severity: str, config: Mail, request) -> None:
|
||||||
logger.debug('Will send mail notification')
|
logger.debug('Will send mail notification')
|
||||||
|
|
||||||
msg = f"""\
|
msg = f"""\
|
||||||
|
@ -39,6 +39,7 @@ URL: {task.url}
|
||||||
Check: {task.check}
|
Check: {task.check}
|
||||||
Status: {severity}
|
Status: {severity}
|
||||||
Time: {result.submitted_at}
|
Time: {result.submitted_at}
|
||||||
|
Previous status: {old_severity}
|
||||||
|
|
||||||
See results of task on {request.url_for('get_task_results', task_id=task.id)}
|
See results of task on {request.url_for('get_task_results', task_id=task.id)}
|
||||||
"""
|
"""
|
||||||
|
@ -73,7 +74,14 @@ Subject: [Argos] {urlparse(task.url).netloc}: status {severity}
|
||||||
smtp.sendmail(config.mailfrom, address, mail)
|
smtp.sendmail(config.mailfrom, address, mail)
|
||||||
|
|
||||||
|
|
||||||
def notify_with_gotify(result, task, severity: str, config: List[GotifyUrl], request) -> None:
|
def notify_with_gotify(
|
||||||
|
result,
|
||||||
|
task,
|
||||||
|
severity: str,
|
||||||
|
old_severity: str,
|
||||||
|
config: List[GotifyUrl],
|
||||||
|
request
|
||||||
|
) -> None:
|
||||||
logger.debug('Will send gotify notification')
|
logger.debug('Will send gotify notification')
|
||||||
headers = {'accept': 'application/json',
|
headers = {'accept': 'application/json',
|
||||||
'content-type': 'application/json'}
|
'content-type': 'application/json'}
|
||||||
|
@ -93,6 +101,7 @@ URL: {task.url}
|
||||||
Check: {task.check}
|
Check: {task.check}
|
||||||
Status: {severity}
|
Status: {severity}
|
||||||
Time: {result.submitted_at}
|
Time: {result.submitted_at}
|
||||||
|
Previous status: {old_severity}
|
||||||
|
|
||||||
See results of task on {request.url_for('get_task_results', task_id=task.id)}
|
See results of task on {request.url_for('get_task_results', task_id=task.id)}
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -60,7 +60,7 @@ async def create_results(
|
||||||
# Don’t create an alert if the severity has not changed
|
# Don’t create an alert if the severity has not changed
|
||||||
if last_severity != severity:
|
if last_severity != severity:
|
||||||
# XXX Use a job queue or make it async
|
# XXX Use a job queue or make it async
|
||||||
handle_alert(config, result, task, severity, request)
|
handle_alert(config, result, task, severity, last_severity, request)
|
||||||
|
|
||||||
db_results.append(result)
|
db_results.append(result)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
Loading…
Reference in a new issue