C2(deploy-infra-alerting): impl fix ntfy payload template syntax

Use confirmed Grafana 12 template functions (coll.Dict, coll.Slice,
coll.Append, data.ToJSON) to build ntfy-native JSON payload.
Previous attempt hit 400 from ntfy — likely malformed output from
incorrect template syntax. This version uses the documented patterns
from Grafana's notification template reference.

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

View file

@ -88,15 +88,16 @@ templates:
name: ntfy-infra
template: |
{{ define "ntfy-infra.payload" -}}
{{ $msg := "" -}}
{{ range .Alerts -}}
{{ $msg = printf "%s%s\n" $msg .Annotations.summary -}}
{{ 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 }}
{{- $msg := "" -}}
{{- range .Alerts -}}
{{- $msg = (printf "%s%s\n" $msg .Annotations.summary) -}}
{{- end -}}
{{- $title := (printf "[%s] %s" (.Status | toUpper) .CommonLabels.alertname) -}}
{{- $actions := coll.Slice -}}
{{- range .Alerts -}}
{{- if .Annotations.runbook_url -}}
{{- $actions = coll.Append (coll.Dict "action" "view" "label" "Open Runbook" "url" .Annotations.runbook_url) $actions -}}
{{- end -}}
{{- end -}}
{{- coll.Dict "topic" "infra-alerts" "title" $title "message" $msg "priority" 3 "actions" $actions | data.ToJSON -}}
{{- end }}