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:
parent
e7f50bc4fd
commit
ae67899bcf
1 changed files with 13 additions and 12 deletions
|
|
@ -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 }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue