0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-11 15:51:19 +00:00

Fix the Spike integration to use Flip.new_status

This commit is contained in:
Pēteris Caune 2024-04-12 15:30:26 +03:00
parent 2913b8faf5
commit 17e9f33bb9
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
5 changed files with 17 additions and 11 deletions

View file

@ -21,7 +21,9 @@ class NotifySmsTestCase(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()

View file

@ -18,7 +18,9 @@ class NotifySpikeTestCase(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()
@ -55,8 +57,8 @@ class NotifySpikeTestCase(BaseTestCase):
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_does_not_escape(self, mock_post: Mock) -> None:
self.check.name = "Foo & Bar"
self.check.status = "up"
self.check.save()
self.flip.new_status = "up"
mock_post.return_value.status_code = 200

View file

@ -1215,17 +1215,19 @@ class Zulip(HttpTransport):
class Spike(HttpTransport):
def notify(self, check: Check, notification: Notification) -> None:
def notify_flip(self, flip: Flip, notification: Notification) -> None:
if not settings.SPIKE_ENABLED:
raise TransportError("Spike notifications are not enabled.")
url = self.channel.value
headers = {"Content-Type": "application/json"}
payload = {
"check_id": str(check.code),
"title": tmpl("spike_title.html", check=check),
"message": tmpl("spike_description.html", check=check),
"status": check.status,
"check_id": str(flip.owner.code),
"title": tmpl("spike_title.html", check=flip.owner, status=flip.new_status),
"message": tmpl(
"spike_description.html", check=flip.owner, status=flip.new_status
),
"status": flip.new_status,
}
self.post(url, json=payload, headers=headers)

View file

@ -1,5 +1,5 @@
{% load humanize %}
{{ check.name_then_code|safe }} is {{ check.status|upper }}.
{% if check.status == "down" and check.last_ping %}
{{ check.name_then_code|safe }} is {{ status|upper }}.
{% if status == "down" and check.last_ping %}
Last ping was {{ check.last_ping|naturaltime }}.
{% endif %}

View file

@ -1 +1 @@
{{ check.name_then_code|safe }} is {{ check.status|upper }}
{{ check.name_then_code|safe }} is {{ status|upper }}