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. FindNodeObject not working (for me)

FindNodeObject not working (for me)

Scheduled Pinned Locked Moved Support
6 Posts 2 Posters 36.7k 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.
  • D
    D
    Dan
    wrote on last edited by
    #1

    Hi!

    I am using 1.0.1.

    I found the following post very helpful,

    @victor said in Action to return value:

    In 1.0.0-rc1 I have added new NXSL function FindNodeObject. It takes two arguments: current node object and ID or name of node of interest. It can be used as following:

    sub main()
    {
       // Search for node named "gateway"
       gw_node = FindNodeObject($node, "gateway");
    
       if (gw_node == null)
          return 0;   // No such node or access denied
    
       // from here, gw_node can be used in a same way as $node, for example:
       status = GetDCIValue(gw_node, FindDCIByDescription(gw_node, "Status"));
    
       return 1;
    }
    

    I have tried doing this with the following code,

    server_name = "" . plaza . ".se"; // this gives me the server name in the var, as this is different depending on which node that the DCI is running on
    server_name_node = FindNodeObject($node, server_name);
    return server_name_node;

    This only gives me "null" which would indicate that the server with the server_name is non-existant.
    But I have also set the node name manually, instead of using the var, which works as it should, but this means a lot of manual work and a generated name in a var is much more flexible 🙂

    So my question is, is there something I am missing, or is it just not possible to use the variable instead of a static argument?

    Best regards,
    Dan

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

      Hi!

      You use variable plaza in your code, but how you initialize it? If you wish to use something based on DCI's node, the only way to access node's attributes is via $node variable. So, for example, if you wish to add "-server" suffix to current node's name and find that node, you should use code like this:

      server = FindNodeObject($node, $node->name . "-server");
      

      Best regards,
      Victor

      1 Reply Last reply
      0
      • D
        D
        Dan
        wrote on last edited by
        #3

        Hi!

        The plaza variable is created like this,

        if ($node->name ~= "^(.*)ru[rf]([0-9]{2})1") {
        	plaza = $1;
        	lane = int64($2);
        }
        

        I just tried changing the creation of the variable "server_name" from,

        server_name = "" . plaza . ".se";
        

        to,

        server_name = plaza . ".se";
        

        And now the following creates a node object,

        server_name_node = FindNodeObject($node, server_name);
        

        It does work now, it seems like it was my creation of the variable "server_name" that was the problem.
        So I guess it was my bad code that just didn't work 🙂

        Thank you for the feedback!

        But, now when I test the script the console application dies

        NETXMS CONSOLE CRASH DUMP
        Sat Jun 26 19:30:54 2010
        
        EXCEPTION: C0000005 (Access violation) at 76EB1FFE
        
        NetXMS Console Version: 1.0.1
        OS Version: Windows NT 6.1 Build 7600
        Processor architecture: Intel x86
        
        Register information:
          eax=00000138  ebx=0012DE20  ecx=00720000  edx=0012DE20
          esi=2AA7F833  edi=0012DE18  ebp=02A9FEEC  esp=02A9FEB8
          cs=001B  ds=0023  es=0023  ss=0023  fs=003B  gs=0000  flags=00010206
        
        Call stack:
          [ntdll:76EB1FFE]: RtlFreeHeap
          [ntdll:76EB1FAF]: RtlFreeHeap
          [MSVCRT:756598CD]: free
          [nxcon:0040B323]: (function-name not available)
          [kernel32:75AF1174]: BaseThreadInitThunk
          [ntdll:76EBB3F5]: RtlInitializeExceptionChain
          [ntdll:76EBB3C8]: RtlInitializeExceptionChain
        

        Adding the .mdmp file.


        nxcon-2804-1277573454.mdmp

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

          Hi!

          You code was correct, it's very strange that it was not working. Adding an empty string should not change result. I suspect bug in NXSL interpreter, but I was unable to reproduce this on my test system - both

          server_name = "" . plaza . ".se";

          and

          server_name = plaza . ".se";

          gives the same correct result in my test script.

          Best regards,
          Victor

          1 Reply Last reply
          0
          • D
            D
            Dan
            wrote on last edited by
            #5

            Hi!

            Hm ok, strange.
            But it works now, so maybe it was just the good ol' user error 🙂

            Thanks for your help though!

            Best regards,
            Dan

            1 Reply Last reply
            0
            • D
              D
              Dan
              wrote on last edited by
              #6

              I thought I could share the result.

              sub main() {
                 numImages = $1;
                 if ($node->name ~= "^(.*)ru[rf]([0-9]{2})1") {
                    plaza = $1;
                    lane = int64($2);
                 }
                 mlc = plaza . "mlc010";
                 mlcNode = FindNodeObject($node, mlc);
                 dciName = "Total number of transactions in Lane " . lane;
                 numTransactions = GetDCIValue(mlc_node, FindDCIByDescription(mlcNode,dciName));
                 return (numImages / numTransactions) * 100;
              }
              

              Best regards,
              Dan

              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