Create System.Shutdown action for entire container

Started by srh, May 29, 2018, 10:42:37 PM

Previous topic - Next topic

srh

I know how to use create an action using "Execute command on remote node via agent" to execute System.Shutdown on an individual node.  Is it possible to create an action that will execute System.Shutdown on every node within a container?  The use-case is that I want to use an event processing policy rule to trigger System.Shutdown for a group of nodes when a certain DCI (UPS remaining runtime) hits a threshold.

gdodd

There are probably a few different ways to do this but this will get you started and you can expand from there.

1. Create the following script in the Script Library (Configuration/Script Library). Here I am assuming that you will have an event policy for each container and will create a script for each container. You could probably pass in the node, get the parent of the node, and use that as your start point so you could have just one script/event.

// Find Container by ID that needs shutdown and start enumeration from it. Replace nnnn with the ID of the container
EnumerateNodes(FindObject(nnnn));

// 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);
if (o->isAgent == 1)
//Put the node into maintenance node
EnterMaintenance(o);
//Uncomment the next line to shutdown the systems
//AgentExecuteAction(o, "System.Shutdown");
//Use the below line to debug and make sure you are working with the intended nodes. You could also just use the Maintenance mode as an indication.
SetCustomAttribute(o, "TestShutdown", "Success");

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


2. Create an Actions Configuration (Configuration/Actions Configuration). Type will be Exectue NXSL script

3. Use the action in your Event Policy

I did basic testing, but nothing extensive. This is intended to get you started (although it may work for you as is).
If you want to test the script, you can use  Tools/Server Console and "exec <scriptname>".

If you have any questions or need further assistance, let me know.

Gary


srh

Excellent solution, Gary.  Your assumption about one policy per container is correct.  I did a bit of testing and it appears that this will fit the bill perfectly.  Putting the nodes into maintenance mode before shutdown is a nice touch, too.

Many thanks!
Shane

Victor Kirhenshtein

Hi,

just one addition - check for "NetObj" class here:

else if (classof(o) == "NetObj")

is unnecessary - GetObjectChildren will only return objects of class NetObj and derivatives. Even more, that way you may miss some nodes on next levels, for example if you have cluster object - then it's class will be "Cluster", not a "NetObj". Simple "else" is enough here.

Best regards,
Victor