Ok, so this is another example of a powershell script turned workflow. Several years ago when we first started deploying VMware here I realized that nobody pays attention to the errors that are generated in vCenter unless they actually trigger alerts. This is my attempt at rectifying that.
This is what we are trying to create:
Since the basic idea of this is pretty simple, get all the events that have a category of ‘error’ from vCenter and send an email listing all the ones found i decided to make it a little fancier to make it interesting.
Here are some of the highlights:
- Uses a configuration object to keep the organization specific settings.
- Utilizes VcEventFilterSpec and createCollectorForEvents to get the events.
- Uses a array of Properties to pass data between actions and workflows.
- Basic regular expressions.
- There is a configuration workflow to configure the report, no need to edit the configuration object by hand.
And that is how you turn a simple task in to a complex but more interesting one…
So let’s get started.
The configuration for the workflow is kept in a configuration object, this means that you don’t have to tweak the workflows or always specify the same things every time you run the script.
The things that are kept in the object is a list of vCenter servers, email address to send the report to and an array of regular expressions that are used to ignore specific error messages.
To configure said object there is a workflow that you can use:
Now that we have that taken care of, the next thing is the main workflow, the daily report.
This workflow has no inputs, it uses the configuration object for everything.
As far as the workflow it self it’s pretty straight forward… get the events for yesterday and output them as html in an email.
There is also a workflow that does not use the configuration object and also only emails the errors for a single vCenter, but this one will let you pick a date range.
The guts of that workflow is pretty much identical to the previous one so I’m not going to include it here.
I also promised some simple regular expressions, here is the one that takes the URL to the vcenter server and turns it in to a simple hostname:
The next thing I needed to do was to get a list of all events that were categorized as errors. To do this you instantitate a VcEventFilterSpec and create a Event Collector, like so:
I’ll be happy to explain any of these things in more detail if anyone wants me to.
The next challenge is how to pass things from one workflow/action to another when you want to pass something other than a built in object type. The way I solved this was to return an array of Properties objects.
As you can see in the middle of that code I am also checking each event against the regular expressions that have been configured to be filtered out. Please note that regular expressions can be hard on the CPU so you probably don’t want to have 100’s of filters…
Once you have the array of Properties you can simply loop over them and build a HTML table:
I’d love to hear your thoughts on what can be improved.
Download package here.