NetXMS Support Forum

English Support => General Support => Topic started by: DesertRat on October 27, 2021, 06:11:35 AM

Title: Interface expected state in template
Post by: DesertRat on October 27, 2021, 06:11:35 AM
Where can I script the expected state of interfaces when a template is applied to node? The purpose is to ignore all interfaces except for the one I'm interested in.

Thanks in advance
Title: Re: Interface expected state in template
Post by: Filipp Sudanov on October 27, 2021, 03:23:13 PM
Changing of interface expected state is possible from NXSL script. We currently do not have option to keep NSXL scripts in templates, so you have to use some sort of global script for this.
Hook::ConfigurationPoll is a good place - it's a standard hook script that is executed on each configuration poll.

A simple example is this:
interfaces = GetNodeInterfaces($node);
foreach(i : interfaces)
{
SetInterfaceExpectedState(i, "IGNORE");
}


but you need a bit more advanced script. You can check, if node is assigned to particular template (in this case node becomes a child object of the template, so you can use e.g. $node->isDirectParent(template_object) method to check this).

You can use mapping tables to keep list of interfaces that should be in "UP" or "DOWN" state if you need to.

Please inform, if you need more information or examples.
Title: Re: Interface expected state in template
Post by: DesertRat on December 05, 2021, 09:14:24 PM
Thank you very much for this. I must be missing something very basic. It looks as though the $node variable is not defined in the hook. I am getting the error: "Error 14 in line 12: Function or operation argument is not an object" just trying to execute this script within Hook::ConfigurationPoll


/* Available global variables:
*  $object - current object, one of 'NetObj' subclasses
*  $node - current object if it is 'Node' class
*
* Expected return value:
*  none - returned value is ignored
*/

sub main()
{
  trace(1,"hook executed for ".$node->ipAddr);
}
Title: Re: Interface expected state in template
Post by: Filipp Sudanov on December 06, 2021, 01:19:27 AM
There are some objects besides nodes that also have configuration poll, e.g. Clusters, which may not have the attributes that node objects have. You can check if the object is node in the beginning of your script, e.g.
if (classof(p) == "Node") {
  ...
}