Create New Custom Variable By Modifying an Existing Variable

How do I create a custom variable which is a modified version of an existing variable?

I have a variable, called “app” which has some hyphens in it. I want to create a new variable (modified_app) that will replace those with an underscore.

For example here, the variable app is “service-quiz-master”. I want the modified_app variable to be “service_quiz_master”.

I’m using Grafana OSS(grafana/grafana:latest on Docker).

@jaganraj Thanks! While the solution is dumb, I was able to achieve this by passing the variable to a Postgres instance which performed the replace operation. Is there a lightweight method to do this which maybe involves a custom program that performs this operation?

Wouldn’t regex also work using a secondary variable?

1 Like

Yes, regexp will be more lightweight, but also more fragile. Let’s say you prepare regexp for string with 3 -. It will be working fine, until someone will create app, which will have more - or someone will make a typo and use --. Regexp is possible, but it will require more knowledge/time to cover all edge cases.

Or heavy brute force :hammer: (e. g. SQL) can be used.

I would use lightweight solution.

2 Likes

Agree. And If the org is not well disciplined in naming things nomenclature, no solution will be good enough.

If people create stuff will nilly, one department calls one thing: mickey-mouse and the other MickeyMouse then… :mouse2: