Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Create System.Shutdown action for entire container

Create System.Shutdown action for entire container

Scheduled Pinned Locked Moved Support
4 Posts 3 Posters 22.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    S
    srh
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G
      G
      gdodd
      wrote on last edited by
      #2

      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);
      		}
      	}
      }
      
      1. Create an Actions Configuration (Configuration/Actions Configuration). Type will be Exectue NXSL script

      2. 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

      1 Reply Last reply
      0
      • S
        S
        srh
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups