Following up on my previous post, Event Based Automation with VMware Dispatch, this one will demonstrate using Dispatch to automate actions when a host enters or exits maintenance mode. The Dispatch function we’re going to create will disable alarm actions on the host when it enters maintenance mode and re-enable alarm actions when the host exits maintenance mode.
Here is the Powershell script to disable/enable alarm actions on a host in vCenter.
This is also available on Github. Save the above code to a file named ‘Set-HostAlarmActions.ps1’ or grab it using curl:
This time to create the Dispatch function we’re going to use a yaml file. Dispatch allows you to define functions (and other things) in yaml files. When you start working with more functions this is a convenient way to define them and it makes it easier to update a function while you are testing it and making frequent changes. Here is the yaml file to define this function.
Now to create the function we just need to reference the yaml file.
And to update the function we simply use dispatch update, referencing the same yaml file.
Once the function is created we just need to subscribe it to the events for a host entering and exiting maintenance mode.
You can have multiple functions in the same yaml file. There’s a more complete example in the documentation on Functions. You can also have different items in the same file, for example combining the function and subscriptions:
Additionally, you can reference the yaml file over http. It appears that the function file (Set-HostAlarmActions.ps1 in this case) does however need to be on the local filesystem, but this breaks the setup down to essentially two commands.
Download the function file:
Create/update everything by referencing the YAML file:
The documentation on yaml files is a little sparse at the moment, but you can retrieve the yaml for an object in Dispatch like so:
Using the output as a template, take the properties and values that you would normally specify on the command line and put those in your yaml file. With a little trial and error you can figure out what’s required.
I’m working on another function to do essentially the same thing with nodes in SolarWinds. If you use SolarWinds for monitoring it will unmanage a host in Solarwinds when it enters maintenance mode and re-manage it when it exits maintenance. Look for a part 2 to this post, hopefully coming soon!