⌠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:
Grafana v9.0.2.
My ValueString returns something like this: [ var='C' labels={device=/dev/mapper/vg_system-lv_root, env=test, fstype=xfs, host=host03, instance=10.10.10.10:9100, job=node-exporter, mountpoint=/} value=1 ], [ var='B' labels={device=/dev/mapper/vg_system-lv_root, env=test, fstype=xfs, host=host03, instance=10.10.10.10:9100, job=node-exporter, mountpoint=/} value=87.20739379429632 ]
I described it in the section âAlertingâ - âAlert rulesâ - âSummary and annotationsâ like this: {{ $value | reReplaceAll [\s"" | reReplaceAll],\s"\n" | reReplaceAll]"" | reReplaceAllvar=â[A-Z0-9a-z]+â\s"" | reReplaceAlllabels={[A-Za-z0-9_-=\s.:,\/]}\s"" | reReplaceAllmetric='(.)â "**$1**: " | reReplaceAllvalue=([0-9.]+) "$1" }}%
And the message comes with two values: 87.35772882917088 and 1. Like this:
âmountpoint: / , host: host03, current value: 87.35772882917088
1â
Could tell me please how to remove value 1 which is in the line [ var='C' labels={device=/dev/mapper/vg_system-lv_root, env=test, fstype=xfs, host=host03, instance=10.10.10.10:9100, job=node-exporter, mountpoint=/} value=1 ]?
Would be great to have Value on Create Alert page on âSummary and annotations section.â with ability to use template values there ($labels $values $value).
Creating new template for just Value formatting is overkill.
I just wondering why not created default template to have behaviour identical to times before to unified alerting?
I can see value of âvalue_stringâ only in Alerting Groups, why not to have back that magic button Alert Preview.
And no matter how I modify message, I canât get value of ValueString, is it working only in template?