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. Instance discovery scripts completely broken?

Instance discovery scripts completely broken?

Scheduled Pinned Locked Moved Support
4 Posts 3 Posters 28.2k 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.
  • M
    M
    Millenium7
    wrote on last edited by
    #1

    I'm confused. Has something drastically changed with how instance discovery works for template DCI's?

    I've followed this guide https://lasiszm.wordpress.com/2017/10/22/netxms-template-for-monitoring-mikrotik-interfaces/ as a baseline
    Except 2 problems, First is EVERY interface is being added as a DCO
    And the second is the names are wrong. Everything just has instance number next to it, i.e. instead of "testRx - ether1" it just shows "testRx - 1" and so on for each

    Then I find the discovery filter script just isn't working at all. I literally place this as the first line "return false;" and it STILL adds every single interface.............. what the hell?

    edit: Ok I think there's a bug. If I have any 'and' or 'or' statements in IF statements anywhere, it seems the result will always return true, even if the very first line of the discovery script is "return false;"

    This works fine

    transport = CreateSNMPTransport($node);
    if (transport == null) return false;
    
    ifName = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.2.".$1);
    ifType = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.3.".$1);
    ifMAC = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.6.".$1);
    // If could not retrieve values, return false
    if (ifName == null) return false;
    if (ifType == null) return false;
    if (ifMAC == null) return false;
    
    // If interface type is 1/other (VPLS shows as this) and MAC begins with 02
    if (ifType->value == 1) return %(true,$1,ifName->value);
    

    but this does not

    transport = CreateSNMPTransport($node);
    if (transport == null) return false;
    
    ifName = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.2.".$1);
    ifType = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.3.".$1);
    ifMAC = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.6.".$1);
    // If could not retrieve values, return false
    if (ifName == null) return false;
    if (ifType == null) return false;
    if (ifMAC == null) return false;
    
    // If interface type is 1/other (VPLS shows as this) and MAC begins with 02
    if (ifType->value == 1) && (ifType->value == 1) return %(true,$1,ifName->value);
    

    This is the exact same script, except the last line if doing 2 IF statements, both are exact same values. This script adds every single interface, as if the result was the very first line said "return true;", even if I put in 'return false;" it'll still add every single interface. Also if I try to condense the failure statements to 1 line i.e.

    if (ifName == null) || (ifType == null) || (ifMAC == null) return false;
    

    Once again it doesn't matter at all what is in the rest of the script. It's like the whole script fails and it just defaults to 'return true;'

    1 Reply Last reply
    0
    • A
      A
      Alex Kirhenshtein
      wrote on last edited by
      #2

      Add brackets in "if":

      if ( ifType->value == 1 && ifType->value == 1 ) return %(true,$1,ifName->value);

      1 Reply Last reply
      0
      • M
        M
        Millenium7
        wrote on last edited by
        #3

        Ok will check

        Either way I still consider this a bug, and quite undesirable. If a patch is pushed that changes the scripting syntax or behavior this will create an absolute mess for instance discovery. Other scripts just outright fail and this is fine. Instance discovery should not default to 'yes accept everything' if there is an issue with the script, it should just outright fail like the others do. Makes it much more obvious to fix

        Is there a way to debug this sort of thing easily? I get no feedback which makes troubleshooting much harder and more time consuming

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #4

          Server generates event SYS_SCRIPT_ERROR for runtime errors in scripts, including instance discovery filter scripts, and also generates "warning" record in server's log. First parameter contains script identification string and second parameter contains error message. Unfortunately event is not generated if there is compilation error like in your case (although warning message in log still generated). I've fixed that in development branch, starting with next release you'll also get SYS_SCRIPT_ERROR event for instance discovery filter compilation errors.

          On a side note, script syntax didn't change in that part - expression like

          if (a < b) && (c < d) { }
          

          was always a syntax error. Whole "if" expression should always be enclosed in parenthesis.

          Best regards,
          Victor

          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