scripting management functions [SOLVED]

Started by sperlm, June 11, 2013, 10:43:40 AM

Previous topic - Next topic

sperlm

Hello,

   I have been creating filtering and even some scripts that imitate snmpwalk or trying to polish tool to mass-create DCI (based on my snmpwalk) but some problems with management functions arised.
(I am looking into python for nxshell functionality now, but I believe commands from Function Reference should be working without nxshell.)

Some functions work, but some do not and I don't know why..

For example - GetNodeParents, GetNodeInterfaces, GetObjectParents, GetObjectChildren

The first line where I use these functions makes the script broken, even test scripts like this are not working...
interfaces = GetNodeInterfaces($1);
foreach(i : interfaces)
{
    println "Interface: name='" . i->name . "' id=" . i->id;
}

All I get is: ERROR: Script finished with error: Error 14 in line 1: Function or operation argument is not an object

Can someone enlighten me what I do wrong please?

With regards

Milan Sperl

Victor Kirhenshtein

Hi!

You pass $1 to GetNodeInterfaces. It's a first argument of the script. It depends on context, but it's unlikely that it will be node object. If you want to work with "current" node (i.e. owner node of DCI in transformation script), you can use built-in variable $node. In other cases, you can use FindNodeObject function to obtain reference to node object you are interested in.

Best regards,
Victor

sperlm

#2
Sorry for not explaining - I am using $1 because I am running the script from Server Console and provide node name as first parameter of course. That is why I am "printing" the results.
I even tried to set node name (or ID) instead of $1 to remove the possibility this parameter is at fault.
If I set node name (e.g. Core1-SW) the error changes to:
_Error 5: Invalid operation with NULL value_

Thanks for the reply

Milan Sperl

Victor Kirhenshtein

Node name is a string, not an object reference. If you want to find node object by name, you could use FindObject or FindNodeObject function, like this:


node = FindNodeObject(null, $1);
println "Node ID: " node->id;


Also check this script example: http://wiki.netxms.org/wiki/Script_Example:_Read_SNMP_Value_From_Node

Best regards,
Victor

sperlm

Thanks for pointing the problem for me.
I should have used the findObject function and I have to use ID of the tested node only. Cannot use Object Name, which is OK for testing purposes, in called scripts I can use $node again.
The "null" parameter in findObjectNode was not clear to me (but it works with it too).

Thanks once more.

Milan Sperl

Victor Kirhenshtein

Quote from: sperlm on June 11, 2013, 07:00:36 PM
The "null" parameter in findObjectNode was not clear to me (but it works with it too).

It's a reference to already known object. Here is the explanation: http://wiki.netxms.org/wiki/SG:Security_Issues.

Best regards,
Victor