Alertmanager: use global string constant/variable in multiply templates

11 views
Skip to first unread message

Eugene Brusilovsky

unread,
Mar 3, 2020, 9:15:36 AM3/3/20
to Prometheus Users
I want to re-use string constant like "KubeDeploymentReplicasMismatch|KubeHpaReplicasMismatch|KubePodNotReady|KubeContainerWaiting" in several Alertmanager template definitions.

let me illustrate by example (I know the below wouldn't work):


{{ $myAlertGroup := "KubeDeploymentReplicasMismatch|KubeHpaReplicasMismatch|KubePodNotReady|KubeContainerWaiting" }}

{{ define "__alert_message_title" -}}
{{ if match .GroupLabels.alertname $myAlertGroup -}}
   {{ .CommonAnnotations.message }}
{{- end }}

{{ define "__alert_message_body" -}}
{{ if match .GroupLabels.alertname $myAlertGroup -}}
      {{- range .Alerts.Firing }}      
      • `{{ .Labels.namespace -}}`/`{{ .Labels.pod -}}`
      {{- end }}
{{- end }}


Is there a way to achieve this?

It's possible to move variable definition inside {{ define .. }} block but then I need to define the same value twice, once per template definition. I want to manage the value in one place. 
Reply all
Reply to author
Forward
0 new messages