0

The setup

For a Contact Point configured to use Slack "Text Body" field contains the following:

{{ if eq .Status "firing" }}
  Type: {{ .CommonLabels.type }}

  {{ range .Alerts }}
    Status: {{ .Status }}

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

    {{ .ValueString }}

    DashboardURL: {{ .DashboardURL }}
  {{ end }}
{{ else }}
  Stabilized
  threshhold: {{ .CommonLabels.threshold }}
  type: {{ .CommonLabels.type }}
{{ end }}

The above works as expected and looks great, with only one exception. In what is output by {{ .ValueString }} I see a lot of valuable data I'd like to access in a more granular/programmatic way. Right now one example of this output is a String that looks like:

"[ metric='twinkie_product_collection Rate' labels={job=twinkie_product_collection, types=runRate} value=1.1111111111111112 ],
[ metric='concert_ticket_collection Rate' labels={job=concert_ticket_collection, types=runRate} value=1.1111111111111112 ]"

The problem is this is an ugly string, I'd like to extract data like the metric, types and value to display in a more formatted way. Similarly to how I'm able to display .Labels data with:

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

I've been referencing the documentation here and the only two KeyValue types I see on an Alert besides .Labels is .Annotations, but when I try to display this annotation data in the same way there is nothing in there. So my main question is:

How can I access and display the data contained in .ValueString in a programmatic way?

Cumulo Nimbus
  • 8,785
  • 9
  • 47
  • 68

1 Answers1

0

You can't. It is a string, so you will need to parse it first, which will be complicated on the Golang template level.

I would recommend to use query, which will group by all required labels + use expression for alert condition. Then customize summary/description, where you can access that "ValueString" in structured way. See example: https://youtu.be/UtmmhLraSnE?t=964 I would say that is Grafana native approach.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59