mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-04 21:05:26 +00:00
Fix the Pushover integration to use Flip.new_status
This commit is contained in:
parent
a485bea2b2
commit
af36078f10
4 changed files with 12 additions and 8 deletions
hc/api
templates/integrations
|
@ -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()
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% if check.status == "down" %}
|
||||
{% if status == "down" %}
|
||||
🔴 {{ check.name_then_code|safe }}
|
||||
{% else %}
|
||||
🟢 {{ check.name_then_code|safe }}
|
||||
|
|
Loading…
Add table
Reference in a new issue