Is there any solution to operate the variable in templating?

I am now using the templating to select the name of the circuit , such as “icmp_anto”,
the name of the variable is test, so when i using $test in the query i can obtain the string “icmp_anto”, but i hope i can get the string “anto”,is there anyway to achieve the function ?

Hi,

You may use the regex field for this when edit template variable so that you only extract “auto”.

Marcus

I’ve tried that , but i failed , because the regex can only filter the result, but it can not modify the job’s name…

So you want to use the selected template value to filter in a query -> you’ll need to use some sort of regex in the query to achieve that. Don’t know what datasource you’re using but most of the time-series databases have this support.

Marcus

ok , i will check that first,thank you

Curious to know, what datasource are you using?

i am now using prometheus as the database

So if you have a template variable named var with value anto you can filter that a label ends with anto in prometheus using something like

<metric>{<label>=~"^.*$var"}

<metric> and <label> should you provide as wanted

Marcus

This is noted, thanks so much