C2(deploy-infra-alerting): impl use custom payload for ntfy-native JSON

Replace Grafana's default webhook JSON with ntfy-native JSON via
payloadTemplate. The template produces:
  {"topic":"infra-alerts","title":"[FIRING] ...","message":"...","actions":[...]}

This gives clean notifications instead of raw Grafana JSON blobs.
Uses coll.Dict/data.ToJSON template functions (Grafana 12+).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erich Blume 2026-03-22 11:18:37 -07:00
commit e7f50bc4fd

View file

@ -7,13 +7,11 @@ contactPoints:
- uid: ntfy-infra-webhook
type: webhook
settings:
url: https://ntfy.ops.eblu.me/infra-alerts
url: https://ntfy.ops.eblu.me
httpMethod: POST
title: >-
{{ template "ntfy-infra.title" . }}
message: >-
{{ template "ntfy-infra.message" . }}
maxAlerts: "0"
payloadTemplate: >-
{{ template "ntfy-infra.payload" . }}
disableResolveMessage: false
policies:
@ -89,13 +87,16 @@ templates:
- orgId: 1
name: ntfy-infra
template: |
{{ define "ntfy-infra.title" -}}
[{{ .Status | toUpper }}] {{ .CommonLabels.alertname }}
{{- end }}
{{ define "ntfy-infra.message" -}}
{{ define "ntfy-infra.payload" -}}
{{ $msg := "" -}}
{{ range .Alerts -}}
{{ .Annotations.summary }}
{{ if .Annotations.runbook_url }}Runbook: {{ .Annotations.runbook_url }}{{ end }}
{{ $msg = printf "%s%s\n" $msg .Annotations.summary -}}
{{ end -}}
{{- end }}
{{ $actions := coll.Slice -}}
{{ range .Alerts -}}
{{ if .Annotations.runbook_url -}}
{{ $actions = coll.Slice (coll.Dict "action" "view" "label" "Open Runbook" "url" .Annotations.runbook_url "clear" false) -}}
{{ end -}}
{{ end -}}
{{ data.ToJSON (coll.Dict "topic" "infra-alerts" "title" (printf "[%s] %s" (.Status | toUpper) .CommonLabels.alertname) "message" $msg "priority" 3 "actions" $actions) -}}
{{ end }}