Grafana-zabbix: Allow regex usage for setAlias function

Created on 5 Oct 2016  路  10Comments  路  Source: alexanderzobnin/grafana-zabbix

I'm submitting a ...

  • [ ] Bug report
  • [x] Feature request
  • [ ] Question / Support request

Would be nice if a regex could be used to set the alias, eg when a regex is used to select the items.

datasource feature request

Most helpful comment

Hmm... I'm not sure if I got your question. Are you asking for a "search and replace" function? If so, this will not do it, since it uses a simple Go Regex, where it do a search using a regular expression and will replace the item.name with the result of the search (the same way any online regex tester will do, where you use a test string and it shows you the 'ouput' of you search).
To search for a pattern and replace it with another string, it would be necessary to create another function that expands this one.

All 10 comments

+1
This is very useful and missing feature!

aliasregex
Hey, last week I was in need of this and then found this out as a feature request... works out that I have made a change of my own to include this, I will be pushing the changes from my branch, hope you can have a fast look at it @alexanderzobnin , it's pretty simple and straight forwards, I have added one more option on Alias menu, "setAliasByRegex", that let you "cut" or do whatever you need with the original item name. Maybe you want to rename it to something else like "setAliasWithRegex" or something like that, I just used the first thing on my mind in time :P

I have attached a image as a example.
On the left side I'm using the newly added option to "cut" the word "%usado" from the items, after using a regex to filter the items. On the right side we can see what I had before using the new alias function

Thanks for the very useful feature! A replacement similar to your example works perfect. But how does this "beast" work? Matching groups? Perl regex? A simple substitution is easier to understand: s/foo (.+) bar/$1/.

Hmm... I'm not sure if I got your question. Are you asking for a "search and replace" function? If so, this will not do it, since it uses a simple Go Regex, where it do a search using a regular expression and will replace the item.name with the result of the search (the same way any online regex tester will do, where you use a test string and it shows you the 'ouput' of you search).
To search for a pattern and replace it with another string, it would be necessary to create another function that expands this one.

I'm not sure, which regex engine is used. The regex shown in your screenshot is not golang, it is pcre. Even it is not Go re2. Lookahead and lookbehind are not supported in re2 (re2 Syntax). It is strange that positive lookahead works, but positive lookbehind does not. (?<=DFP ).+ (like your example) triggers an error. Which regex engine is used? Confused.

hmm, strange, I was almost sure that it was golang regex, since I used the same function that is invoked by the text filter on text metrics. Maybe @alexanderzobnin could answer this.

This code executes on client side. So it should be JavaScript regex.

With current implementation it's quite problematic to get some text between two words (e.g.: "steal" from "CPU steal time"), as JS don't support positive lookbehind like this: (?<=CPU ).*?(?= time)

Matching group would be much simpler approach:
CPU (.*) time

So let's make the match group number configurable?
https://github.com/alexanderzobnin/grafana-zabbix/blob/dcbc67d26cb9e54d9a661e99953cf8e79286d02e/src/datasource-zabbix/dataProcessor.js#L179

Yea, I should make alias functions more flexible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b1nary1 picture b1nary1  路  4Comments

heyrod picture heyrod  路  7Comments

xiaoxue999 picture xiaoxue999  路  3Comments

moisesreis picture moisesreis  路  6Comments

samyscoub picture samyscoub  路  6Comments