FindNodeObject not working (for me)

Started by Dan, June 26, 2010, 05:29:27 AM

Previous topic - Next topic

Dan

Hi!

I am using 1.0.1.

I found the following post very helpful,

Quote from: Victor Kirhenshtein on February 25, 2010, 06:40:53 PM
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

Victor Kirhenshtein

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

Dan

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.

Victor Kirhenshtein

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

Dan

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

Dan

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