One of the task when configuring a vCenter is to setup the alarm notifications. But to configure 268 alarms by hand…. well it is just a scary task when you do it via the gui / webclient.
In short I created this script that you can find on my github.
The full story
So I googled around on PowerCLI scripts to change the alarm, and I found some nice scripts. But they didnt’t fit my scripting template… so I developed a script based on the one I found. (https://fixingitpro.com/2012/07/09/powercli-script-to-automatically-setup-vcenter-alarm-email-notification/)
set-vCenter AlarmEmail.ps1 is a powershell script to setup e-mail notifications according to predefined settings. Using a CSV file you can set for each Alarm which profile or alarmClass it should be configured with.
These alarmclasses are defined in a separate parameters.ps1 file.
My way of thinking is that I don’t want variable values fixed in my script.
When I programmed PLC systems, you always defined them separately. And a clean way of coding is to define them on top of your script.
I wanted to have them in a separate file, so that colleagues can use my scripts but don’t have to work through the code to change them.
So I have one object $p that contains these settings. $P is a hashtable that is defined in parameters.ps1.
In a nutshell
The script checks if the alarmClasses in the CSV file are defined as profiles in the parameters file.
Then it will group the Alarms in the CSV by the alarmClasses and configure the alarms according to their profile. (in a for each loop)
I predefined some alarmclasses, these are
- disabled – to disable the alarm completely
- noEmail – to remove all sendemail alarmactions / email notifications of an alarm
- low – alarms that only send once an email notification on state change (green to yellow, yellow to red, or the opposite way)
- medium – sames as low, but also repeating the notifications every 24 hours until the alarm is reset
- high – same as medium but notifying every 4 hours.
An alarmclass contains the following settings
- [bool] disabled – the alarm is disabled
- [array][string] emailTO – array of strings containing one or more e-mail address for notification.
- [string] emailSubject – The e-mai subject the notification gets. I would use keywords so e-mails can easily be filtered by e-mail clients.
- [int] repeatMinutes – Frequency of repeating the notifications in minutes.
You can find my script on github via this link
The script is part of my code-repository on github. The code-repository contains (or is going to contain) several scripts that I use and are free under the MIT license.