… it did not display anything and everything in the template after that point failed to display, which I assume means there was an error (not sure where that gets logged, if it does).
I am still playing with several other methods and have yet to be able to figure out the best way to just grab that value. I probably need to brush up on my golang templating skills. In the meantime, does anyone know of a good way to grab that measurement value?
Thanks for sharing @jlcrow! This is exactly the sort of formatting I was looking for. It’s really not easy to format these strings to get back to the pre-unified alerting sort of formatting.
Yeah, I was taken off guard too, considering most are probably using the information from the old alert style and the template doesn’t give you a real way to deal with it, just a ValueString. I’d love to figure out how to get my dashboard images back in slack too.
*edit: I figure it out; it was the regex for labels not expecting to be labels={}. Updated the template at the very end of this post; just swapped the + for * to match zero to unlimited instead of 1 to unlimited.
So I’m seeing a scenario where I am getting output with the following from the above set of reReplaceAlls and I can’t wrap my head around why it is keeping labels={} in here:
**Network 1 2u via pfsense** : labels={} 96
The fille ValueString is: [ var='E0' metric='Network 1 (2u) via pfsense' labels={} value=92.83333333333333 ]
I thought it might be parenthesis so I tried to remove them and then the ValueString was: [ var='E0' metric='Network 1 2u via pfsense' labels={} value=95.8 ]
But I still have the same output.
Here is my full contact point template:
{{ define "__discord_text_alert_list" }}{{ range . }}{{ with .ValueString }}
{{- . | reReplaceAll `\[\s` "" | reReplaceAll `\],\s` "\n" | reReplaceAll `\]` "" | reReplaceAll `var='[A-Z0-9a-z]+'\s` "" | reReplaceAll `labels=\{[A-Za-z0-9_\-\=\s\.:,]+\}\s` "" | reReplaceAll `metric='(.*)' ` "**$1**: " | reReplaceAll `value=([0-9\.]+)` "$1" }}
{{ end }}
{{ if gt (len .PanelURL) 0 }}**Panel**: {{ .PanelURL }}{{ end }}
{{ end }}{{ end }}
{{ define "discord.message" }}{{ if gt (len .Alerts.Firing) 0 }}**[ALERTING]**
{{ template "__discord_text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**[RESOLVED]**
{{ template "__discord_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}
I have other scenarios where I am seeing the output just as I expect: