Slack message won't render value

I am trying to get current value from query in Slack message but unfortunately I am getting {{ humanize $values.A.Value }} instead.

My Slack message template:

{{ define "alert_severity_prefix_emoji" -}}
	{{- if ne .Status "firing" -}}
		:white_check_mark:
	{{- else if eq .CommonLabels.severity "critical" -}}
		:red_circle:
	{{- else if eq .CommonLabels.severity "warning" -}}
		:warning:
	{{- end -}}
{{- end -}}

{{ define "slack.title" -}}
  {{ template "alert_severity_prefix_emoji" . }}
	[{{- .Status | toUpper -}}{{- if eq .Status "firing" }} x {{ .Alerts.Firing | len -}}{{- end }}]: {{ .CommonLabels.alertname -}}
{{- end -}}

{{- define "slack.text" -}}
{{- range .Alerts -}}
{{ if gt (len .Annotations ) 0 }}
*Description*: {{ .Annotations.description }}
*Instance*:
{{ range .Labels.SortedPairs }}{{ if or (eq .Name "env") (eq .Name "instance") }}• {{ .Name }}: `{{ .Value }}`
{{ end }}{{ end }}
*Silence alert*: {{ .SilenceURL }}
*Go to dashboard*: {{ .DashboardURL }}
*Go to panel directly*: {{ .PanelURL }}
{{ end }}
{{ end }}
{{ end }}

Alert configuration:




grafana_4

what I am doing wrong?

Hi! :wave:

You need to use the value of the Classic Condition B. You can’t use the value of A as it is a query and queries can return anywhere between 10s and 10,000s of data points, and Grafana doesn’t know which one you want.

We have some documentation explaining this here Templating labels and annotations | Grafana documentation

Hi George,
No, it won’t work either I’ve tried earlier and it was returning <no value> in Slack message. I found the issue. It doesn’t work with classic expressions etc. I managed to make it working by creating two expressions: Reduce and Math:

I wanted to attach a screenshot but unfortunately I am getting: ExternalUploadHelpers::ExternalUploadValidationError error

Hi! When using Classic Conditions you need to use the RefID and offset of the condition, as explained here. For example:

The first condition is {{ $values.B0 }}, and the second condition is {{ $values.B1 }}
1 Like

Thats useful information! Thanks, I didn’t find it earlier.