11

I am a new developer in Grafana and I would like to have a query that returns a variable having "CA" at the END of its name.

I was using SEARCH key code but it seems that it returns only the contained characters while I am really interested in the location of those characters.

As an example, I wrote this query :

SELECT cmts_device SEARCH CA

And it shows me this as a result :

enter image description here

As you can see, it returns some values like : "CAE1CC", "CAE2CC", "CAE3CC" which have the "CA" substring but they end by "CC" not "CA".

How can I fix this pleaase ? Thank you for any help !

salamanka44
  • 904
  • 3
  • 17
  • 36
  • try this regex: **^[A-Z0-9]*(?=CA$)** – Tayyab Mazhar Nov 21 '20 at 21:29
  • still didn't work for me I really dont understand why !!! – salamanka44 Nov 22 '20 at 10:24
  • What type of the datasource are you using? Is it really this type of filtering supported by the datasource? – Jan Garaj Nov 23 '20 at 23:27
  • @JanGaraj It sounds like the datasource is [JSON](https://grafana.com/grafana/plugins/simpod-json-datasource) but not specifically what version of that plugin though. – Bitcoin Murderous Maniac Nov 28 '20 at 19:53
  • @salamanka44 Did you find a solution to this? Why have you not given more specific detail about your data source JSON? Read comments from other answers too, you can still get help from people here if you simply put more detail about your data source. Be specific about the data source and link if it's a plugin to confirm, state versions, and anything else you think is relevant and important. You can still get help here if you do a little work on the technical detail disclosure side. Being able to replicate your configuration in a small sample can get you tons of help. – Bitcoin Murderous Maniac Nov 30 '20 at 02:17

2 Answers2

0

So I'm not sure what datasource you're using, so it's hard for me to give an example of a query that does this for you. But, you can use the regex field inside Grafana. This will work for any datasource. Here I'm using Prometheus, but again the actual query and datasource does not matter.

So for example, say I have a query returning container IDs:

non-filetered results

And I only wanted the container IDs that ended with the letter "b". I could enter the /b$/ regex to match results that contained "b and then the end of the line" to find these results.

filtered results

In your example, you would enter /CA$/.

Jacob Colvin
  • 2,625
  • 1
  • 17
  • 36
  • I tried this ("/CA$/" in regex field) and I swear that it returns no result after this !!!!! I don't know why, it's getting me crazy!! Maybe it's due to the datasource or something like this that I didn't understand yet – salamanka44 Nov 21 '20 at 20:59
  • just a question please : do you think that's still possible to get the same result using the SEARCH keyword or any other keyword ? (i mean without using the "regex field" ??? – salamanka44 Nov 21 '20 at 21:28
  • Odd - what version of Grafana are you running? Also what is the actual datasource you're using? (e.g. mysql, oracle, etc) – Jacob Colvin Nov 21 '20 at 23:13
  • the version is Grafana v7.0.3 (00ee734baf) and I think that the datasource here is json (we have a mysql database) – salamanka44 Nov 22 '20 at 10:14
  • So I downgraded to 7.0.3 and it's still working for me. But I actually need the name of the data source plugin you're using. You can go to `http:///datasources` and see the plugin type on the right side of each data source. I would like to replicate your setup, but the query you issue isn't valid in any data source I'm aware of (including MySQL). – Jacob Colvin Nov 22 '20 at 21:48
  • I believe OP has answered about using datasource [JSON](https://grafana.com/grafana/plugins/simpod-json-datasource) but not specifically what version of that plugin though. The appear to have versions of Grafana they are compatible with per that link. Can you emulate without the actual JSON content the OP is using though enough to test the regex query. Ping me back so I can read up on what you determine, might be helpful to others too. – Bitcoin Murderous Maniac Nov 28 '20 at 19:51
  • @BitcoinMurderousManiac So reading more into this the JSON plugin actually wraps other APIs that implement /search, /query etc. So that would mean OP is running some custom backend api that's working with this. So I really don't know how I could replicate that unless they come back and post details about what actually they're running, and in the case that it is the JSON datasource, a link to the (hopefully) OSS that it's implementing. AFAIK there isn't a sample API you can use to test the JSON datasource. Perhaps I am wrong. – Jacob Colvin Nov 29 '20 at 23:07
0

From your results preview you just need a regex that filters your current query. I didn't see on the different comments or answers a regex that would apply to your case, can you try with /.*CA$/ ?

enter image description here

First comment by @Tayyab : enter image description here

On the answer by @Jacob:

enter image description here

nandilov
  • 699
  • 8
  • 18
  • With Grafana filtering you just need to match any part of the result, not the entire result. Items are only excluded if no characters in the string are matched. (This is at least the behavior with 7.0+ and default data sources. Admittedly I have not tested everything.) – Jacob Colvin Nov 29 '20 at 19:56