Alertmaanger template for Pagerduty

62 views
Skip to first unread message

David Derkach

unread,
Sep 10, 2024, 3:59:41 AM9/10/24
to Prometheus Users
Hello community,
I have written this template for notifications to pagerduty:

pagerduty.tmpl: |- 
  {{ define "pagerduty.one_line" -}} 
     [{{ .Status | toUpper }}:{{ .Alerts.Firing | len }}] {{ .CommonLabels.alertname }} - 
     {{ range .Alerts }} 
       {{- if .Annotations.description -}} 
          {{ .Annotations.description }} 
       {{- else if .Annotations.message -}} 
         {{ .Annotations.message }} 
       {{- else -}} 
         No additional details provided. 
       {{- end }} 
       {{- "\n" -}} 
       {{ end }} 
   {{- end }}

Here how i referenced it in my receiver config:
  receivers: - name: 'pagerduty'
  pagerduty_configs: 
     - service_key: f73*** 
       description: '{{ template "pagerduty.one_line" . }}' 
       send_resolved: true

Issue: I can`t see notifications in Pagerduty but in Slack, were I use another template I can see notification.
My alertmanager pod show below logs:

ts=2024-09-10T07:58:35.002Z caller=dispatch.go:353 level=error component=dispatcher msg="Notify for alerts failed" num_alerts=2 err="pagerduty/pagerduty[0]: notify retry canceled due to unrecoverable error after 1 attempts: failed to template PagerDuty v1 message: template: :1:12: executing \"\" at <{{template \"pagerduty.one_line\" .}}>: template \"pagerduty.one_line\" not defined"
Reply all
Reply to author
Forward
0 new messages