diff --git a/.pylintrc b/.pylintrc index 041c69d..c5b3cdd 100644 --- a/.pylintrc +++ b/.pylintrc @@ -441,7 +441,9 @@ disable=raw-checker-failed, singleton-comparison, missing-module-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 # either give multiple identifier separated by comma (,) or put this option diff --git a/argos/server/alerting.py b/argos/server/alerting.py index 52723df..7c07533 100644 --- a/argos/server/alerting.py +++ b/argos/server/alerting.py @@ -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 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""" 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 \ '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 \ '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') msg = f"""\ @@ -39,6 +39,7 @@ URL: {task.url} Check: {task.check} Status: {severity} Time: {result.submitted_at} +Previous status: {old_severity} 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) -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') headers = {'accept': 'application/json', 'content-type': 'application/json'} @@ -93,6 +101,7 @@ URL: {task.url} Check: {task.check} Status: {severity} Time: {result.submitted_at} +Previous status: {old_severity} See results of task on {request.url_for('get_task_results', task_id=task.id)} """ diff --git a/argos/server/routes/api.py b/argos/server/routes/api.py index d43e080..244f499 100644 --- a/argos/server/routes/api.py +++ b/argos/server/routes/api.py @@ -60,7 +60,7 @@ async def create_results( # Don’t create an alert if the severity has not changed if last_severity != severity: # 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.commit()