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?