Asking for a help with to put the server name from the event to the alert text

Hello!
I’m asking for help to get the “common_name” value from the event text and put it into alert.
I literally broke my head trying to do this task, but this Go-powered template editor is too hard for me to understand. Mostly due of lack of documentation and examples.
Can you help me to write this small section? It needs to get all of the “common_name=” hosts and put it into the alert’s text.

example of the event string:
[ var='B0' metric='x509_cert.distinct { common_name: server1.domain.com }' labels={common_name=server1.domain.com} value=2.424371e+06 ], [ var='B1' metric='x509_cert.distinct { common_name: server2.domain.com }' labels={common_name=server2.domain.com} value=2.424486e+06 ], [ var='B2' metric='x509_cert.distinct { common_name: server3.domain.com }' labels={common_name=server3.domain.com} value=2.424426e+06 ]

Well… I solved this by adding the following:

{{ with .ValueString }}{{ reReplaceAll "[[][^]]*metric='{?([^}']*})?'[^]]* labels={common_name=([^}']*)}? ]? value=([^}']*[0-9])?" "$2" . }}
{{ end }}

Where:
Desired value is “selection group 2” (put regex into regex101.com)
$2 is calling output of “selection 2”, aka “shell variable”

1 Like