Query variable regex

Hello community

  • What Grafana version and what operating system are you using?
    10.4.3

  • What are you trying to achieve?
    I try to replace variable query from influxdb with regex with specific value
    For exemple i use some query whitch give me result :
    ILO2_test or ILO4_test or ILO25_test

i want toget back a variable list with 2 for ILO2_test , 4 for ILO4_test and 0025 for ILO25_test

  • How are you trying to achieve it?
    with regex but nor found good one if exist

  • What happened?
    nothing

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No error

ty a lot

I I’ve searched the forum extensively and found nothing that seems to indicate this is possible.

Maybe there is another way to achieve this?

For example, can we apply transformations to variables directly in the dashboard?

Not sure if I understand your question correctly… Do you want to initialize several dashboard variables from your single query?

Or do you just want to perform some regex-based postprocessing on values returned by your query?
If this is the case, flux’s regexp package could help:

|> map(fn: (r) => {
    tmp_ = regexp.replaceAllString(r: /^ILO/, t: "", v: r["txt"])
    num = regexp.replaceAllString(r: /_test$/, t: "", v: tmp_)
    return { r with num: num }
})

hello,
Thx you for your answer

In fact it is a little bit tricky.

I have one variable $nbr witch use query in influxdb to get the list off one field with some object

In the name of there object i have a number. that i want to extract 2 4 025.

ILO2_test
ILO4_test
ILO025_test

I can’t modify infludb entry so i can’t modify the list of object

and i need to exctract the number in variable to use it later

so i use regex like

.ILO([^_]).*

and it is done , my variable contain list with 2 4 025

But the issu is: 025 should be 0.25 for my dahsboard calculation.

In my visualisation query i use this number to calculate some thing

select last(“value”) * $nbr FROM “…” WHERE “…” GROUP BY “…”

so my calculation are ok with 2 or 4 but false with 025 instead of 0.25

i’m not sure i’m clear :slight_smile:

PS: i have influxb 1.8.0 so flux is not available

Ok, so this is your more or less expected result:

With flux it is pretty easy:

|> map(fn: (r) => {    
    tmp_ = regexp.replaceAllString(r: /^ILO/, t: "", v: regexp.replaceAllString(r: /^ILO0/, t: "0.", v: r["txt"]))
    num = regexp.replaceAllString(r: /_test$/, t: "", v: tmp_)
    return { r with num: num }
})

Not sure about InfluxQL though.

As for using variables in transformations, it is possible:

Just enable necessary feature toggle:

1 Like

TY for your help i will manage with this