Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Regex on Instance Discovery

Regex on Instance Discovery

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 26.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L
    L
    Luis Montaño
    wrote on last edited by
    #1

    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)

    1 Reply Last reply
    0
    • L
      L
      Luis Montaño
      wrote on last edited by
      #2

      Any Help?

      1 Reply Last reply
      0
      • T
        T
        Tursiops
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups