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