Monday, 17 September 2012

vCenter Alarms - bulk "Set Email Notification" change

Recently I have installed a new vCenter server and, as a good practice, was going to to configure the most critical Alarms to send email to my mailbox. Surely, it was going to be manual process as I have zero scripting knowledge except the PowerCLI minimum which was part of VCAP exam. But frankly speaking, I barely remember half of the PowerCLI command  I used to know.

However, I thought I might try to refresh my rusty PoweCLI knowledge. Therefore, I picked up the first article in search results which provided a good PS script for vCenter 5.0 and useful links for automation of the boring process of setting "Send Email" action for all Alarms. Definitely, there is still no descent explanation why VMware hasn't provided such configuration option.

While I was applying this script to my infrastructure I found out that number of Alarms differ from version to version. Here, in my company we have vCenter 5.0 Update 1a in production and vCenter 5.1 in test environment. Therefore, I have decided to adjust the script for both our versions.

So, here are the links to the scripts which might be useful for you.
There are plenty opportunities to customize these scripts for more sophisticated actions, but for my scarce PoweCLI skills just an email is more than enough :)

If you find this post useful please share it with any of the buttons below.

3 comments:

  1. Oh my, it changes with every update / version?! Painful. VMware should keep better tabs on their api

    ReplyDelete
  2. What das that error mean?:

    Get-AlarmDefinition -Name “$actAlarm1" | Get-AlarmAction | New-AlarmActionTrigger <<<< -StartStatus 'Red' -EndStatus 'Yellow' -Repeat
    + CategoryInfo : NotSpecified: (:) [New-AlarmActionTrigger], InvalidArgument
    + FullyQualifiedErrorId : Client20_AlarmServiceImpl_NewAlarmActionTrigger_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Alarm.NewAlarmActionTrigger

    ReplyDelete
  3. To make this easier, you can get the alarm names dynamically and set them into an array then act on the array name. This also allows the script to account for any custom alarms:

    $alarms = Get-AlarmDefinition | Select -ExpandProperty "Name"
    Get-AlarmDefinition -Name $alarms | Get-AlarmAction | Remove-AlarmAction -Confirm:$false
    Get-AlarmDefinition -Name $alarms | New-AlarmAction -Email -To $MailTo

    etc, etc.

    Hope this helps anyone else out there looking to do this!

    ReplyDelete