Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow regex usage for setAlias function #287

Closed
1 of 3 tasks
hans-d opened this issue Oct 5, 2016 · 10 comments
Closed
1 of 3 tasks

Allow regex usage for setAlias function #287

hans-d opened this issue Oct 5, 2016 · 10 comments

Comments

@hans-d
Copy link

hans-d commented Oct 5, 2016

I'm submitting a ...

  • Bug report
  • 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.

@evandro-portugal
Copy link
Contributor

+1
This is very useful and missing feature!

@evandro-portugal
Copy link
Contributor

evandro-portugal commented Jan 17, 2017

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

@sesom42
Copy link

sesom42 commented Feb 15, 2017

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/.

@evandro-portugal
Copy link
Contributor

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.

@sesom42
Copy link

sesom42 commented Feb 15, 2017

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.

@evandro-portugal
Copy link
Contributor

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.

@alexanderzobnin
Copy link
Collaborator

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

@landergate
Copy link

landergate commented Apr 16, 2017

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

@alexanderzobnin
Copy link
Collaborator

Yea, I should make alias functions more flexible.

@alexanderzobnin
Copy link
Collaborator

see http://docs.grafana-zabbix.org/reference/functions/#replacealias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants