Create a simple (legacy style) notification template

After upgrading from 8.5 to 9.4, the alerting notifications (in slack) got a ton more verbose. After recreating all my alerts from scratch to fix some conversion issues, I’m still having difficulty removing all the garbage and getting a functional and simplified notification in slack.

As an example:


^ This is what the alerts used to look like. Minimal, but with the pertinent information. “lag” showing what metric we’re alerting on. “host” showing the scope of the alert. And then the value (doesn’t include a unit, but is a minor issue).


^ This is the closest I’ve been able to get using the following template:

  {{ range .Alerts.Firing }}
  {{ .ValueString }}
  {{ end -}}

The problem with this is that because I have to use a “reduce” function to select the last value from the series, and then a “threshold” function to define when to trigger, this dumps data for each function in the message, along with the unwanted var='X'.

How can I further strip this down to only show only the same information as before, and nothing more? The metric name, the scope (series labels), and the value from the query.

This might help:

{{ define "short-message" }}
    {{ range .Alerts }}
    {{ (.Labels).Hostname }} has {{ (.Labels).present_value }} threshold for {{ (.Labels).alertname }} that started at {{ printf "%.19s" .StartsAt }}
    {{ end }}
{{ end }}