Goopalo David
Goopalo David

Reputation: 19

Alertmanager template for Pagerduty

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 }}

enter image description here

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"

I have tried to comment reference to template in description and with default alertmanager tempalte it works as expected.

Upvotes: 0

Views: 153

Answers (0)

Related Questions