NetXMS Support Forum

English Support => General Support => Topic started by: sNsReal on May 19, 2020, 02:59:06 AM

Title: Auto-bind script for new node
Post by: sNsReal on May 19, 2020, 02:59:06 AM
Hi again and sory for my following question, im new to NetXMS and i am having some headaches trying to do simple tasks.
Here it goes

I need to make an auto-bind script template to bind new nodes to a specific container

Something like this:

return $node->isNew bind to container "container";

How can i achieve this simple script? i cant find the correct syntax to make it work


Thanks!
Title: Re: Auto-bind script for new node
Post by: johnnyva on May 21, 2020, 03:28:50 AM
Hey sNsReal,

You could probably use the newly available creationTime attribute on the NetObj class (added sometime in v3) which is epoch of when the object was created.

So on the container that you want nodes to autobind to, you could enable "Automatically bind nodes selected by filter to this container", and disable the unbind option.
And your filtering script would be something like this:


HOURS_IN_SECONDS = 3600;
if($node->creationTime != 0 && (time() - $node->creationTime) < HOURS_IN_SECONDS) return true;


This will bind nodes that have been created within the last hour.  So long as the node performs a config poll within that time, then it should bind.
If it does not return true, then it will implicitly return null, and null means that it won't bind or unbind the node being processed.
If the object was created prior to the CreationTime being added to NetXMS, then CreationTime will be 0.
Title: Re: Auto-bind script for new node
Post by: sNsReal on May 21, 2020, 07:45:09 PM
Thanks!!!!

It works very well!

But the problem that i need to solve is that i need to bind the nodes matched by the template to "infrastructure Services\new nodes" container so i can then organize them in infrastructure.