Add e-mail alerts to all 41 default vSphere 4.1 alarms

Towards the end of a customer’s virtualization implementation we’re doing some clean-up of the environment. During the initial setup I was using my own local email address to test various alerting processes, of which there are several. For instance, every SQL Server maintenance task sends a success/failure e-mail alert, the NetApp Virtual Storage Console plug-in can be configured to e-mail an administrator after snapshots are taken, and the Dell iDRAC can send e-mails on hardware status changes. All those are fairly quick to configure or lack a way to script a quick solution. But with 40 default alarms in vSphere, three vCenters, and being lazy as I am, I knew there must be a better solution than right clicking 120 alarms and copying-and-pasting an email address. As the proverb goes, if you repeat it, script it. So I set out to find how PowerCLI could help me.

Coming from a Windows background, I’m an old VBScript guy. I know that many solutions have already been discovered and scripted to accomplish many of the very same or similar tasks you’re trying to solve. Copying code and modifying to suit your needs is a way of life for a Windows admin. So when I came across this blog post at VMPros, I knew I had something I could work with.

As is usually the case, the script doesn’t do exactly what I need it to do, but the gist of it is definitely there. All I want is to do is add the “Send a notification email” action, set the email address, and include a notification event for a green to yellow transition. The end result of what I want is shown below.

Here’s what I came up with:

#Found at VMPros
# Connect vCenter server
$vCenterServer = “vcenter-server”
$user = “administrator”
$pass = “password”

if ( $DefaultVIServers.Length -lt 1 )
Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null

$MailToDefault1 = “”

# Default Alarm Definitions
$actAlarm1 = “Cannot connect to storage”
$actAlarm2 = “Cluster high availability error”
$actAlarm3 = “Exit standby error”
$actAlarm4 = “External I%2fO workload detected on a datastore”
$actAlarm5 = “Health status changed alarm”
$actAlarm6 = “Health status monitoring”
$actAlarm7 = “Host Baseboard Management Controller status”
$actAlarm8 = “Host battery status”
$actAlarm9 = “Host connection and power state”
$actAlarm10 = “Host connection failure”
$actAlarm11 = “Host cpu usage”
$actAlarm12 = “Host error”
$actAlarm13 = “Host hardware fan status”
$actAlarm14 = “Host hardware power status”
$actAlarm15 = “Host hardware system board status”
$actAlarm16 = “Host hardware temperature status”
$actAlarm17 = “Host hardware voltage”
$actAlarm18 = “Host IPMI System Event Log status”
$actAlarm19 = “Host memory status”
$actAlarm20 = “Host memory usage”
$actAlarm21 = “Host processor status”
$actAlarm22 = “Host service console swap rates”
$actAlarm23 = “Host storage status”
$actAlarm24 = “License error”
$actAlarm25 = “License inventory monitoring”
$actAlarm26 = “License user threshold monitoring”
$actAlarm27 = “Migration error”
$actAlarm28 = “Network connectivity lost”
$actAlarm29 = “Network uplink redundancy degraded”
$actAlarm30 = “Network uplink redundancy lost”
$actAlarm31 = “No compatible host for Secondary VM”
$actAlarm32 = “Status of other host hardware objects”
$actAlarm33 = “Timed out starting Secondary VM”
$actAlarm34 = “Virtual machine cpu usage”
$actAlarm35 = “Virtual machine error”
$actAlarm36 = “Virtual machine Fault Tolerance state changed”
$actAlarm37 = “Virtual Machine Fault Tolerance vLockStep interval Status Changed”
$actAlarm38 = “Virtual machine high availability error”
$actAlarm39 = “Virtual machine memory usage”
$actAlarm40 = “VMKernel NIC not configured correctly”
$actAlarm41 = “Datastore usage on disk”

# Add E-mail alert and create Alarm Trigger
Get-AlarmDefinition -Name “$actAlarm1”, “$actAlarm2”, “$actAlarm3”, “$actAlarm4”, “$actAlarm5”, “$actAlarm6”, “$actAlarm7”, “$actAlarm8”, “$actAlarm9”, “$actAlarm10”, “$actAlarm11”, “$actAlarm12”, “$actAlarm13”, “$actAlarm14”, “$actAlarm15”, “$actAlarm16”, “$actAlarm17”, “$actAlarm18”, “$actAlarm19”, “$actAlarm20”, “$actAlarm21”, “$actAlarm22”, “$actAlarm23”, “$actAlarm24”, “$actAlarm25”, “$actAlarm26”, “$actAlarm27”, “$actAlarm28”, “$actAlarm29”, “$actAlarm30”, “$actAlarm31”, “$actAlarm32”, “$actAlarm33”, “$actAlarm34”, “$actAlarm35”, “$actAlarm36”, “$actAlarm37”, “$actAlarm38”, “$actAlarm39”, “$actAlarm40”, “$actAlarm41” | New-AlarmAction -Email -To “$MailToDefault1”
Get-AlarmDefinition -Name “$actAlarm1”, “$actAlarm2”, “$actAlarm3”, “$actAlarm4”, “$actAlarm5”, “$actAlarm6”, “$actAlarm7”, “$actAlarm8”, “$actAlarm9”, “$actAlarm10”, “$actAlarm11”, “$actAlarm12”, “$actAlarm13”, “$actAlarm14”, “$actAlarm15”, “$actAlarm16”, “$actAlarm17”, “$actAlarm18”, “$actAlarm19”, “$actAlarm20”, “$actAlarm21”, “$actAlarm22”, “$actAlarm23”, “$actAlarm24”, “$actAlarm25”, “$actAlarm26”, “$actAlarm27”, “$actAlarm28”, “$actAlarm29”, “$actAlarm30”, “$actAlarm31”, “$actAlarm32”, “$actAlarm33”, “$actAlarm34”, “$actAlarm35”, “$actAlarm36”, “$actAlarm37”, “$actAlarm38”, “$actAlarm39”, “$actAlarm40”, “$actAlarm41” | Get-AlarmAction | New-AlarmActionTrigger -StartStatus “Green” -EndStatus “Yellow”
# Disconnect vCenter server;
Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false

Note that I’m using PowerCLI 5 on a 4.1U1 environment. This script will perform the actions I want, but when I run it, I do get errors – but again, it seems to perform the actions I want. The error I get says that I’m passing invalid arguments to the New-AlarmActionTrigger cmdlet. But it adds the notification email action, the email address, and the green to yellow transition as I want, so I’m not looking much further. If you happen to find out why it gives this error, feel free to leave a comment and let me know!



4 Comments on “Add e-mail alerts to all 41 default vSphere 4.1 alarms”

  1. karlochacon says:

    does it work for vCenter 5?

    thanks a lot

  2. No, the script does not work with vCenter 5 as is. vCenter 5 includes more alarm definitions than those included in 4.1. Some simple additions to the script for the added definitions should do the trick, though.

  3. […] examples of people who had already done this before me, so I figured it would be pretty easy.  VirtuallyMikeBrown had created a script for vSphere 4.1, but it wasn’t updated for vSphere 5 and only had a single email address. […]

  4. Thanks for the script Mike. I created my own script that handles the alarms a bit differently to make it easier to customize. I also added the ability to have different priorities of notifications and different frequencies. It was built based on the vSphere 5 alarms but could be modified pretty easily to work with 4.1 or even custom alarms.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s