Send single message per alert

  • What Grafana version and what operating system are you using?
    v8.4.1 hosted on Kubernetes

  • What are you trying to achieve?
    Send a single alert for each alert (state change).

  • How are you trying to achieve it?
    Added a template, called SingleAlertContent :

{{ define "SingleAlertContent" }}
  Value: {{ or .ValueString "[no value]" }}

  Labels:
  {{ range .Labels.SortedPairs }}
    {{ .Name }}: {{ .Value }}
  {{ end }}

  {{ if gt (len .Annotations) 0 }}
  Annotations:
  {{ range .Annotations.SortedPairs }}
    {{ .Name }}: {{ .Value }}
  {{ end }}
  {{ end }}

  {{ if gt (len .DashboardURL ) 0 }}
    Go to dashboard: {{ .DashboardURL }}
  {{ end }}
  {{ if gt (len .PanelURL) 0 }}
    Panel: {{ .PanelURL }}
  {{ end }}
{{ end }}

Added another template, called SingleAlertTitle:

{{ define "SingleAlertTitle" }}
  [{{ .Status | toUpper }}] {{ .Labels.alertname }} {{ if gt (len .Alerts.Firing) 0 }}firing:{{ .Alerts.Firing | len }}{{ end }}
{{ end }}

Used the templates in my default, Slack, contact point:

  • Title: {{ template “SingleAlertTitle” . }}
  • Text Body: {{ template “SingleAlertContent” . }}

Fired a test notification from within the contact point.

  • What happened?
    A Slack message was sent with only the state [FIRING] (from the title) in it.
    Grafana APP 1052
    This is what the same test notification looks like, without the templates:

  • What did you expect to happen?
    Get a Slack message that contains the details for the single alert.
    The actual goal is to get a single message for each alert, like we did before in Grafana v7.
    The templates in the snippets above, or just an attempt to achieve this.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Bump

(not sure if this is allowed, but I’m really stuck here… :pray:)

1 Like

Try to use {{ .CommonLabels.alertname }} instead of {{ .Labels.alertname }}.