Difference between revisions of "Script Example: Enumerate All Nodes"

From NetXMS Wiki
Jump to navigation Jump to search
Line 1: Line 1:


{| style="border-spacing: 20px; border: 20px solid red;"
{| style="border-spacing: 20px; border: 20px solid red;"
|
|
'''WARNING''': This page is no longer updated. Please visit '''[https://www.netxms.org/documentation/nxsl-latest/ NetXMS Scripting Language]''' for current version of the documentation.  
'''WARNING''': This page is no longer updated. Please visit '''[https://www.netxms.org/documentation/nxsl-latest/#_examples_2 NetXMS Script examples]''' for current version of the documentation.  
|}
|}





Revision as of 16:18, 5 October 2020


WARNING: This page is no longer updated. Please visit NetXMS Script examples for current version of the documentation.



Requirements

Enumerate all nodes in NetXMS database.


Solution

Create script in script library which will find "Entire Networks" object and walk down the tree. This script can be executes as an action from event processing policy, or directly from server debug console via exec command.

In order to be able to access info about all nodes, the CheckTrustedNodes server configuration variable needs to be set to 0.

// Find "Entire Network" object and start enumeration from it
EnumerateNodes(FindObject(1));

// This function walks object tree recursively starting from given root
sub EnumerateNodes(rootObject)
{
	// Walk all child objects
	foreach(o : GetObjectChildren(rootObject))
	{
		if (classof(o) == "Node")
		{
			// Process node object
			trace(1, "  + " . o->name);
		}
		else if (classof(o) == "NetObj")
		{
			// For all other objects, go down the tree
			// There can be additional checks for object class, like
			// if (o->type == 5)
			EnumerateNodes(o);
		}
	}
}