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

Improve Opsgenie notifications (include description, schedule, link...)

This commit is contained in:
Pēteris Caune 2024-04-19 11:58:35 +03:00
parent 577602ae21
commit 7f03a9e738
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
5 changed files with 44 additions and 15 deletions

View file

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Show status changes (flips) in check's log page (#447)
- Implement dynamic favicon in the projects overview page (#971)
- Add support for system theme (#978, @moraj-turing)
- Improve Opsgenie notifications (include description, schedule, link etc.)
### Bug Fixes
- Fix hc.front.views.docs_search to handle words "AND", "OR", "NOT" as queries

View file

@ -54,9 +54,27 @@ class NotifyOpsgenieTestCase(BaseTestCase):
payload = mock_post.call_args.kwargs["json"]
self.assertEqual(payload["alias"], self.check.unique_key)
self.assertIn("""The check "Foo" is DOWN.""", payload["message"])
self.assertIn("""The check "Foo" is DOWN.""", payload["description"])
self.assertIn("Last ping was 10 minutes ago.", payload["description"])
self.assertIn("Last ping was 10 minutes ago.", payload["note"])
details = payload["details"]
self.assertIn("cloaked", details["Full details"])
self.assertEqual(details["Last ping"], "10 minutes ago")
self.assertEqual(details["Total pings"], 112233)
@patch("hc.api.transports.curl.request", autospec=True)
def test_it_handles_oncalendar_schedule(self, mock_post: Mock) -> None:
self._setup_data(json.dumps({"key": "123", "region": "us"}))
self.check.kind = "oncalendar"
self.check.schedule = "Mon 2-29"
self.check.tz = "Europe/Riga"
self.check.save()
mock_post.return_value.status_code = 202
self.channel.notify(self.flip)
payload = mock_post.call_args.kwargs["json"]
details = payload["details"]
self.assertEqual(details["Schedule"], "<code>Mon 2-29</code>")
self.assertEqual(details["Time zone"], "Europe/Riga")
@patch("hc.api.transports.curl.request", autospec=True)
def test_opsgenie_with_legacy_value(self, mock_post: Mock) -> None:
@ -138,5 +156,7 @@ class NotifyOpsgenieTestCase(BaseTestCase):
self.assertEqual(n.error, "")
payload = mock_post.call_args.kwargs["json"]
self.assertNotIn("Last ping was", payload["description"])
self.assertNotIn("Last ping was", payload["note"])
details = payload["details"]
self.assertIn("cloaked", details["Full details"])
self.assertEqual(details["Last ping"], "Never")
self.assertEqual(details["Total pings"], 0)

View file

@ -559,8 +559,24 @@ class Opsgenie(HttpTransport):
ctx = {"check": check, "ping": self.last_ping(flip)}
payload["tags"] = cast(JSONValue, check.tags_list())
payload["message"] = tmpl("opsgenie_message.html", **ctx)
payload["note"] = tmpl("opsgenie_note.html", **ctx)
payload["description"] = tmpl("opsgenie_description.html", **ctx)
payload["description"] = check.desc
details = {}
details["Project"] = check.project.name
if ping := self.last_ping(flip):
details["Total pings"] = ping.n
details["Last ping"] = naturaltime(ping.created).replace("\xa0", " ")
else:
details["Total pings"] = 0
details["Last ping"] = "Never"
if check.kind == "simple":
details["Period"] = format_duration(check.timeout)
if check.kind in ("cron", "oncalendar"):
details["Schedule"] = f"<code>{check.schedule}</code>"
details["Time zone"] = check.tz
details["Full details"] = check.cloaked_url()
payload["details"] = details
url = "https://api.opsgenie.com/v2/alerts"
if self.channel.opsgenie.region == "eu":

View file

@ -1,4 +0,0 @@
{% load hc_extras humanize %}
The check "{{ check.name_then_code }}" is DOWN.
{% if check.kind == "simple" %}Expecting to receive a ping every {{ check.timeout|hc_duration }}.{% endif %}
{% if ping %}Last ping was {{ ping.created|naturaltime }}.{% endif %}

View file

@ -1,4 +0,0 @@
{% load hc_extras humanize %}
{% if check.kind == "simple" %}Expecting to receive a ping every {{ check.timeout|hc_duration }}.{% endif %}
{% if ping %}Last ping was {{ ping.created|naturaltime }}.{% endif %}