Regex on Instance Discovery
-
Hi everyone,
I was looking for a way to create a dci for network traffic on all interface address.
I'm using a template and instance discovery for the process. Now I know that I can use the agent list "Net.InterfaceList" to get interface index and then with Net.Interface.BytesIn64({instance}) get the data I need.
I use following Instance discovery filter script that Alex Kirhenshtein created:
if ($1 ~= "^([0-9]+) .*")
{
return %(true, $1); // at this point $1 contains first matching group
}
return false;I was trying to modify regex string to "^[0-9](?!.*127\.0\.0\.1)" to avoid loopback interface.
But I get error "execution error: Error 18 in line 3: Invalid regular expression"
As I couldn't find a way to do it, I use following script
if ((index($1,"127.0.0.1/8")==0)&&(index($1,"::1/128")==0)&&(index($1,"fe80:")==0))
{
if ($1 ~= "^([0-9]+) .*")
{
return %(true, $1); // at this point $1 contains first matching group
}
}
return false;Now it works but I tested my regex string on others apps and it worked fine.
Also I was reading that with regex you can "split" the agent list string into multiple values, for example $1:iface Index, $2:IP Address, etc.
although now is working, I'm a bit confuse about regex expressions on netxms. how could I do it the same I do but with regex?
also, when you use regex to get multiple values from a string, how could you asign to multiple variables ($1,$2,etc) -
Any Help?
-
Hi,
Looks to me like negative lookahead regular expressions are not working (I tested a bit and got the same result you did).
Not sure if there's some syntax difference or if the ?! is being interpreted by something else.You could change your
if ($1 ~= "^([0-9]+) .*")to this
if ( ($1 ~= "^([0-9]+) .*") && ( ! ( $1 ~= "^[0-9]+ (127|::1|fe80).*" ) ) ) {It should work and remove the need for the additional if statement you added, but in the end, it's still just a workaround for the negative lookahead not working properly.
Cheers
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login