From fe9bb0d1e58eca9ffe8339229397c1bfeee73e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= <cuu508@gmail.com> Date: Fri, 12 Apr 2024 14:17:12 +0300 Subject: [PATCH] Fix the Apprise integration to use Flip.new_status --- hc/api/tests/test_notify_apprise.py | 4 +++- hc/api/transports.py | 11 +++++------ templates/integrations/apprise_description.html | 4 ++-- templates/integrations/apprise_title.html | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/hc/api/tests/test_notify_apprise.py b/hc/api/tests/test_notify_apprise.py index ed96e986..64fc1209 100644 --- a/hc/api/tests/test_notify_apprise.py +++ b/hc/api/tests/test_notify_apprise.py @@ -27,7 +27,9 @@ class NotifyAppriseTestCase(BaseTestCase): self.check = Check(project=self.project) self.check.name = "Foo" - self.check.status = "down" + # Transport classes should use flip.new_status, + # so the status "paused" should not appear anywhere + self.check.status = "paused" self.check.last_ping = now() - td(minutes=61) self.check.save() diff --git a/hc/api/transports.py b/hc/api/transports.py index c9a36075..3043d024 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -1088,21 +1088,20 @@ class Trello(HttpTransport): class Apprise(HttpTransport): - def notify(self, check: Check, notification: Notification) -> None: + def notify_flip(self, flip: Flip, notification: Notification) -> None: if not settings.APPRISE_ENABLED: # Not supported and/or enabled raise TransportError("Apprise is disabled and/or not installed") a = apprise.Apprise() - title = tmpl("apprise_title.html", check=check) - body = tmpl("apprise_description.html", check=check) + check, status = flip.owner, flip.new_status + title = tmpl("apprise_title.html", check=check, status=status) + body = tmpl("apprise_description.html", check=check, status=status) a.add(self.channel.value) notify_type = ( - apprise.NotifyType.SUCCESS - if check.status == "up" - else apprise.NotifyType.FAILURE + apprise.NotifyType.SUCCESS if status == "up" else apprise.NotifyType.FAILURE ) if not a.notify(body=body, title=title, notify_type=notify_type): diff --git a/templates/integrations/apprise_description.html b/templates/integrations/apprise_description.html index 5604e5d4..6c9aa56d 100644 --- a/templates/integrations/apprise_description.html +++ b/templates/integrations/apprise_description.html @@ -1,5 +1,5 @@ {% load humanize %} -{{ check.name_then_code }} is {{ check.status|upper }}. -{% if check.status == "down" and check.last_ping %} +{{ check.name_then_code }} is {{ status|upper }}. +{% if status == "down" and check.last_ping %} Last ping was {{ check.last_ping|naturaltime }}. {% endif %} diff --git a/templates/integrations/apprise_title.html b/templates/integrations/apprise_title.html index 29274284..f00a13d1 100644 --- a/templates/integrations/apprise_title.html +++ b/templates/integrations/apprise_title.html @@ -1 +1 @@ -{{ check.name_then_code }} is {{ check.status|upper }} +{{ check.name_then_code }} is {{ status|upper }}