Unknown Object Attribute and Method

Started by jpaquin1106, March 13, 2023, 09:43:28 PM

Previous topic - Next topic

jpaquin1106

I'm currently learning NXSL to write scripts for executing ssh commands to nodes but have immediatelly run into issues that i'm unable to pinpoint the issue based on their documentation here:https://www.netxms.org/documentation/nxsl-latest/#_introduction

1 sub main() {
2 node = Objects.FindNodeByIPAddress($1, null);
3
4 if (node == NULL) {
5 println("Error: node not found.");
6    }
7
8 //println(node->name);
9   println(node->executeSSHCommand("ip address print"));
10}

When I try to execute the code above, it says "Error 30 in line 9: Unknown object's method" claiming the executeSSHCommand method doesn't exist, yet based on Node documentation is does. 

When commenting that line out and uncommenting line 8, it says the attribute doesn't exist. 
However, in documentation, it does. 

I'm unsure at this point if I'm missing something obvious syntactically or what.

Any help would be appreciated.

johnnyva

Hey jp,

I was thinking that maybe node was null, but then I think that would give a different error.

What comes back if you print classof(node)?  I'm expecting it to be Node, but maybe its actually coming back as something else and not returning a node like the docs say.

What server version are you running?

jpaquin1106

#2
Quote from: johnnyva on March 14, 2023, 06:21:08 AMHey jp,

I was thinking that maybe node was null, but then I think that would give a different error.

What comes back if you print classof(node)?  I'm expecting it to be Node, but maybe its actually coming back as something else and not returning a node like the docs say.

What server version are you running?


Okay so after doing a classof(node) call its coming back with "Error 14 in line 8: Function or operation argument is not an object".
With this now known, I've run typeof(node) and its saying its a String.
Printing this string actually prints "Node@0x7f92ac7b6170".

Based on the documentation here: https://www.netxms.org/documentation/nxsl-latest/#_objects it states

FindNodeByIPAddress(ipaddress, currentNode) => Node

Return
Instance of Node object or null if not found or not accessible

So it seems its trying to return a node object but is instead doing an internal call to a toString() method before returning it.
I'm just going based on my knowledge of Java since that "Node@0x7f92ac7b6170" matches what I'm assuming exactly.


Edit:

I'm running the follow:

Server version: 4.3.2 (build 4.3-374-g4f45f9ba5c)
Java version: 11.0.10
JVM: OpenJDK 64-Bit Server VM 11.0.10+9


I've seen rare issues occur when running later versions of OpenJDK but documentation says the latest minimal version is 11 so I should be alright.

edit 2:

I've tested each of the find functions and they are all returning the same string representation.
To clarify, trusted node checks are disabled (by default) so the 2nd parameter is optional based on documentation.

Victor Kirhenshtein

FindNodeByIPAddress is a function, so you should not add "Objects." in front of it. Dot is string concatenation operation in NXSL (we plan to change that in 5.0, but that's another story) - so Objects . FindNodeByIPAddress concatenates null value converted to empty string from non-existent variable "Objects" with object returned by FindNodeByIPAddress converted to string - so result is a string.
Correct script will be something like this:
node = FindNodeByIPAddress($1, null);
if (node == NULL) {
   println("Error: node not found.");
   return;
}

println(node->name);
println(node->executeSSHCommand("ip address print"));

Best regards,
Victor