Browse Source

Improve PagerDuty notifications

- Include additional data in the "details" key
- Don't escape HTML characters in the "description" field

cc: #600
pull/617/head
Pēteris Caune 2 years ago
parent
commit
b56f27e4e2
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
  1. 1
      CHANGELOG.md
  2. 16
      hc/api/transports.py
  3. 4
      templates/integrations/pd_description.html
  4. 6
      templates/integrations/pd_last_ping.html

1
CHANGELOG.md

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Update email bounce handler to mark email channels as disabled (#446)
- Update Signal integration to use JSON RPC over UNIX socket
- Update the "Add TOTP" form to display plaintext TOTP secret (#602)
- Improve PagerDuty notifications
### Bug Fixes
- Disable HTML escaping in Pushover notification titles (#606)

16
hc/api/transports.py

@ -15,6 +15,7 @@ from hc.accounts.models import Profile
from hc.api.schemas import telegram_migration
from hc.front.templatetags.hc_extras import sortchecks
from hc.lib import emails, jsonschema
from hc.lib.date import format_duration
from hc.lib.string import replace
@ -359,6 +360,20 @@ class PagerDuty(HttpTransport):
if not settings.PD_ENABLED:
raise TransportError("PagerDuty notifications are not enabled.")
details = {
"Project": check.project.name,
"Total pings": check.n_pings,
"Last ping": tmpl("pd_last_ping.html", check=check),
}
if check.desc:
details["Description"] = check.desc
if check.tags:
details["Tags"] = ", ".join(check.tags_list())
if check.kind == "simple":
details["Period"] = format_duration(check.timeout)
if check.kind == "cron":
details["Schedule"] = check.schedule
description = tmpl("pd_description.html", check=check)
payload = {
"service_key": self.channel.pd_service_key,
@ -367,6 +382,7 @@ class PagerDuty(HttpTransport):
"description": description,
"client": settings.SITE_NAME,
"client_url": check.details_url(),
"details": details,
}
self.post(self.URL, json=payload)

4
templates/integrations/pd_description.html

@ -1,5 +1,5 @@
{% if check.status == "down" %}
{{ check.name_then_code }} is DOWN
{{ check.name_then_code|safe }} is DOWN
{% else %}
{{ check.name_then_code }} received a ping and is now UP
{{ check.name_then_code|safe }} received a ping and is now UP
{% endif %}

6
templates/integrations/pd_last_ping.html

@ -0,0 +1,6 @@
{% load humanize %}
{% if check.last_ping %}
{{ check.last_ping|naturaltime }}
{% else %}
Never
{% endif %}
Loading…
Cancel
Save