From 3a7f4863edb4228aac9c20405edc462e8dc00307 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Thu, 28 Nov 2024 10:11:39 +0100 Subject: [PATCH] send mailgun slack alert only with perm failure --- scipost_django/apimail/api/views/integrations.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scipost_django/apimail/api/views/integrations.py b/scipost_django/apimail/api/views/integrations.py index de31cf933..357a7baf9 100644 --- a/scipost_django/apimail/api/views/integrations.py +++ b/scipost_django/apimail/api/views/integrations.py @@ -41,15 +41,16 @@ def send_mailgun_alert_slack_message(event_data: dict): if "scipost" in recipient and error_contains_keyword: return - message = f"[{event.upper()} / {reason}] {subject}\n{sender} -> {recipient}\nError: {error_description}" + if event == "failed" and (event_data.get("severity", "unknown") == "permanent"): + message = f"[{event.upper()} / {reason}] {subject}\n{sender} -> {recipient}\nError: {error_description}" - response = requests.post( - settings.SLACK_WEBHOOK_URL_MAILGUN_ALERTS, - json={"text": message}, - headers={"Content-type": "application/json"}, - ) + response = requests.post( + settings.SLACK_WEBHOOK_URL_MAILGUN_ALERTS, + json={"text": message}, + headers={"Content-type": "application/json"}, + ) - return response + return response @csrf_exempt -- GitLab