Script Example: Enumerate All Nodes

Revision as of 12:12, 9 July 2012 by Victor (talk | contribs) (Created page with "'''Requirements''' Enumerate all nodes in NetXMS database. '''Solution''' Create script in script library which will find "Entire Networks" object and walk down the tree. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

// 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);
		}
	}
}