0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-10 23:40:11 +00:00

Fix the Zulip integration to use Flip.new_status

This commit is contained in:
Pēteris Caune 2024-04-12 15:43:06 +03:00
parent 6631a5f76a
commit 5bdb01baf9
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
4 changed files with 9 additions and 6 deletions

View file

@ -19,7 +19,9 @@ class NotifyZulipTestCase(BaseTestCase):
self.check = Check(project=self.project)
self.check.name = "Foobar"
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

@ -1197,21 +1197,22 @@ class Zulip(HttpTransport):
raise TransportError(message)
def notify(self, check: Check, notification: Notification) -> None:
def notify_flip(self, flip: Flip, notification: Notification) -> None:
if not settings.ZULIP_ENABLED:
raise TransportError("Zulip notifications are not enabled.")
topic = self.channel.zulip.topic
if not topic:
topic = tmpl("zulip_topic.html", check=check)
topic = tmpl("zulip_topic.html", check=flip.owner, status=flip.new_status)
url = self.channel.zulip.site + "/api/v1/messages"
auth = (self.channel.zulip.bot_email, self.channel.zulip.api_key)
content = tmpl("zulip_content.html", check=flip.owner, status=flip.new_status)
data = {
"type": self.channel.zulip.mtype,
"to": self.channel.zulip.to,
"topic": topic,
"content": tmpl("zulip_content.html", check=check),
"content": content,
}
self.post(url, data=data, auth=auth)

View file

@ -1,6 +1,6 @@
{% load hc_extras humanize %}
[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ check.status|upper }}**. {% if check.status == "down" and check.last_ping %}Last ping was {{ check.last_ping|naturaltime }}.{% endif %}
[{{ check.name_then_code }}]({{ check.cloaked_url }}) is **{{ status|upper }}**. {% if status == "down" and check.last_ping %}Last ping was {{ check.last_ping|naturaltime }}.{% endif %}
{% if check.desc %}
---

View file

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