diff --git a/hc/api/tests/test_notify_pushover.py b/hc/api/tests/test_notify_pushover.py index c415e2d1..40152573 100644 --- a/hc/api/tests/test_notify_pushover.py +++ b/hc/api/tests/test_notify_pushover.py @@ -21,7 +21,9 @@ class NotifyPushoverTestCase(BaseTestCase): ) -> None: self.check = Check(project=self.project) self.check.name = "Foo" - self.check.status = status + # 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 6bcc23d8..50755f6a 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -670,7 +670,7 @@ class Pushover(HttpTransport): return int(prio) == -3 - def notify(self, check: Check, notification: Notification) -> None: + def notify_flip(self, flip: Flip, notification: Notification) -> None: if not settings.PUSHOVER_API_TOKEN: raise TransportError("Pushover notifications are not enabled.") @@ -687,21 +687,23 @@ class Pushover(HttpTransport): if not TokenBucket.authorize_pushover(user_key): raise TransportError("Rate limit exceeded") + check = flip.owner # If down events have the emergency priority, # send a cancel call first - if check.status == "up" and down_prio == "2": + if flip.new_status == "up" and down_prio == "2": url = self.CANCEL_TMPL % check.unique_key cancel_payload = {"token": settings.PUSHOVER_API_TOKEN} self.post(url, data=cancel_payload) ctx = { "check": check, + "status": flip.new_status, "ping": self.last_ping(check), "down_checks": self.down_checks(check), } text = tmpl("pushover_message.html", **ctx) title = tmpl("pushover_title.html", **ctx) - prio = up_prio if check.status == "up" else down_prio + prio = up_prio if flip.new_status == "up" else down_prio payload = { "token": settings.PUSHOVER_API_TOKEN, diff --git a/templates/integrations/pushover_message.html b/templates/integrations/pushover_message.html index 1bd789d2..e5cb1cc0 100644 --- a/templates/integrations/pushover_message.html +++ b/templates/integrations/pushover_message.html @@ -1,5 +1,5 @@ {% load hc_extras humanize linemode %}{% linemode %} -{% if check.status == "down" %} +{% if status == "down" %} {% line %}The check <b>{{ check.name_then_code }}</b> is <b>DOWN</b>.{% endline %} {% else %} {% line %}The check <b>{{ check.name_then_code }}</b> is now <b>UP</b>.{% endline %} @@ -36,9 +36,9 @@ {% line %}{% endline %} {% if down_checks %} {% if down_checks|length > 10 %} - {% line %}{{ down_checks|length }} other checks are {% if check.status == "down" %}also{% else %}still{% endif %} down.{% endline %} + {% line %}{{ down_checks|length }} other checks are {% if status == "down" %}also{% else %}still{% endif %} down.{% endline %} {% else %} - {% line %}The following checks are {% if check.status == "down" %}also{% else %}still{% endif %} down:{% endline %} + {% line %}The following checks are {% if status == "down" %}also{% else %}still{% endif %} down:{% endline %} {% for c in down_checks %} {% line %}• <b>{{ c.name_then_code }}</b> (last ping: {{ c.last_ping|naturaltime|default:"never" }}){% endline %} {% endfor %} diff --git a/templates/integrations/pushover_title.html b/templates/integrations/pushover_title.html index 465dc6e9..bb8e47b9 100644 --- a/templates/integrations/pushover_title.html +++ b/templates/integrations/pushover_title.html @@ -1,4 +1,4 @@ -{% if check.status == "down" %} +{% if status == "down" %} 🔴 {{ check.name_then_code|safe }} {% else %} 🟢 {{ check.name_then_code|safe }}