NetXMS Support Forum

English Support => General Support => Topic started by: mmarin11 on August 15, 2021, 09:37:13 PM

Title: Template autoapply rules
Post by: mmarin11 on August 15, 2021, 09:37:13 PM
Dear community.

I'm trying to apply a template for ICMP monitoring to devices that are under specific containers and I'm having issues with the Automatic apply rule configuration

for (p : $node->parents) {
   if (p->type == 5 && (p->id==109031 || p->id==42342))
      return true;
}

What would be the best way to apply a template if the device is under specific containers?

Has someone used the new function isDirectParent(object)?

Thank you






Title: Re: Template autoapply rules
Post by: Filipp Sudanov on August 16, 2021, 02:06:16 PM
chances are that adding
else
{
  return false;
}

will fix the issue.


In overall you can use
trace(0, "your debug");
PollerTrace("your debug");
to debug what's happeing. First one adds to server log, the latter - to the output of poll messages when you do e.g. Configuration poll from node's context menu.
Title: Re: Template autoapply rules
Post by: lweidig on August 16, 2021, 02:56:31 PM
In addition to what Filipp stated the screenshot attached does not actually match the code in the message.  You simply have return; and not return true;.  I would probably not include the return false; in an else clause either, but simply as the last statement so that anything falling through gets tagged like this. 
Title: Re: Template autoapply rules
Post by: mmarin11 on August 17, 2021, 08:31:30 PM
The code that worked is:

Thanks Filipp/Iweidig


parents = GetNodeParents($node);
for (p : parents) {
   if (p->type == 5 && (p->id==109031 || p->id==55839 ||p->id==177))
        {
      
      return true;
   }
}
return false;
Title: Re: Template autoapply rules
Post by: lweidig on August 17, 2021, 08:37:04 PM
Glad to hear it is working, mark topic [SOLVED]!