SMBs

Change vCenter alarm notifications using VMware PowerCLI

It can be a nuisance to change vCenter alarm notifications, unless you use this script that allows you to automate the process.

VMware vCenter alarm notifications can be annoying to set and reset. If you have notifications sent to individuals, you need to change them if they leave the company, or you need to add new ones, or maybe you have a few vCenters for which you need to set the alarms. This script makes it easier to do all these things, and you only need to change a couple parameters to get it going in your environment. (Read this VMware blog post for details about how to install PowerCLI.)

vCenterAlarmNotificationChanges.ps1:
#April 15, 2013, Version 1.0, Lauren Malhoit
#You'll need to have the PowerCLI installed to run this script.
#
#This script is meant to change the Actions data in the defined alarms in vCenter. Specifically it will #change the email addresses where the notifications are sent.
#This script will work with vSphere 5.0, but there may be changes to the naming conventions of alarms #in more recent vSphere versions.
#Your alarm action notifications and triggers may differ from the ones shown here. This script allows you #to easily cut and paste the alarms in different places.
#
#Things to change:
$vCenter = "vCenterServer"
$EmailAddresses = "user1@company.com","user2@company.com","user3@company.com"
#
#
Connect-VIserver "$vCenter"
#
#
#
#-----Alarms with Email Notifications-----
$EmailAlarms = "alarm.com.vmware.vcDr.SanArrayDisconnected",`
"alarm.com.vmware.vcDr.SanGroupInvalidatedEvent",`
"alarm.com.vmware.vcDr.SanGroupVmInvalidatedEvent",`
"Protected VM Limit Exceeded",`
"Protection Group Limit Exceeded",`
"Cannot connect to storage",`
"Datastore Connection",`
"Exit standby error",`
"Host Baseboard Management Controller status",`
"Host battery status",`
"Host cannot reach isolation address",`
"Host connection and power state",`
"Host connection failure",`
"Host cpu usage",`
"Host hardware fan status",`
"Host hardware power status",`
"Host hardware system board status",`
"Host hardware temperature status",`
"Host hardware voltage",`
"Host IPMI System Event Log status",`
"Host memory status",`
"Host memory usage",`
"Host processor status",`
"Host service console swap rates",`
"Host storage status",`
"Insufficient vSphere HA failover resources",`
"License error",`
"Network connectivity lost",`
"Network uplink redundancy degraded",`
"Network uplink redundancy lost",`
"Status of other host hardware objects",`
"Virtual machine cpu usage",`
"Virtual machine error",`
"Virtual machine memory usage",`
"Virtual machine total disk latency",`
"VMKernel NIC not configured correctly",`
"vSphere HA failover in progress",`
"vSphere HA host status",`
"vSphere HA virtual machine failover failed",`
"Datastore usage on disk",`
"Incomplete Consistency Group",`
"License Expiring"`
"Low Disk Space",`
"Low Memory",`
"Remote Site Down",`
"Remote Site Ping Failed"
#
#
#
#-----Alarm notifications Send Email From Green to Yellow, Yellow to Red, and Yellow to Green-----
$ThreeNotifiesGYYRYG = "alarm.com.vmware.vcDr.SanArrayDisconnected",`
"alarm.com.vmware.vcDr.SanGroupInvalidatedEvent"
#
#
#
#-----Alarm notifications Send Email From Green to Yellow and Yellow to Red-----
$TwoNotifiesGYYR = "alarm.com.vmware.vcDr.SanGroupVmInvalidatedEvent",`
"Protected VM Limit Exceeded",`
"Protection Group Limit Exceeded",`
"Incomplete Consistency Group",`
"License Expiring",`
"Low Disk Space",`
"Low Memory",`
"Remote Site Down",`
"Remote Site Ping Failed"
#
#
#
#-----Alarm notifications Send Email From Yellow to Red and Yellow to Green-----
$TwoNotifiesYRYG = "Cannot connect to storage",`
"Datastore Connection",`
"Exit standby error",`
"Host Baseboard Management Controller status",`
"Host battery status",`
"Host cannot reach isolation address",`
"Host connection and power state",`
"Host connection failure",`
"Host cpu usage",`
"Host hardware fan status",`
"Host hardware power status",`
"Host hardware system board status",`
"Host hardware temperature status",`
"Host hardware voltage",`
"Host IPMI System Event Log status",`
"Host memory status",`
"Host memory usage",`
"Host processor status",`
"Host service console swap rates",`
"Host storage status",`
"Insufficient vSphere HA failover resources",`
"License error",`
"Network connectivity lost",`
"Network uplink redundancy degraded",`
"Network uplink redundancy lost",`
"Status of other host hardware objects",`
"Virtual machine cpu usage",`
"Virtual machine error",`
"Virtual machine memory usage",`
"Virtual machine total disk latency",`
"VMKernel NIC not configured correctly",`
"vSphere HA failover in progress",`
"vSphere HA host status",`
"vSphere HA virtual machine failover failed"
#
#
#
#-----Alarm notifications Send Email From Yellow to Red-----
$OneNotifyYR = "Datastore usage on disk"
#
#
#
#-----Send a notification trap From Yellow to Red-----
$NotifyTrapYR = "Health status changed alarm",`
"License capacity monitoring",`
"License inventory monitoring",`
"License user threshold monitoring",`
"Migration error",`
"No compatible host for Secondary VM",`
"Remote Site Up",`
"Timed out starting Secondary VM",`
"vSphere HA virtual machine monitoring error"
#
#
#
#-----No Alarm Notifications-----
$NoAlarms = "Cannot find vSphere HA master agent",`
"Datastore capability alarm",`
"Datastore cluster is out of space",`
"Datastore is in multiple datacenters",`
"External IO workload detected on a datastore",`
"Health status monitoring",`
"Pre-4.1 host connected to SIOC-enabled datastore",`
"Recovery Plan Execute End",`
"Recovery Plan Execute Test Begin",`
"Recovery Plan Execute Test End",`
"Recovery Plan Started",`
"Storage DRS not supported on host",`
"Storage DRS recommendation",`
"Thin-provisioned LUN capacity exceeded",`
"Virtual machine Fault Tolerance state changed",`
"vSphere HA virtual machine monitoring action"
#
#
#
#-----CLEAN UP: Remove current emails set in Alarm Actions-----
Foreach ($Alarm in $EmailAlarms) {
Get-AlarmDefinition -Name "$Alarm" | Get-AlarmAction | Remove-AlarmAction -Confirm:$false
}
#
#
#
#-----NOTIFICATIONS: Puts email addresses in for Send Email From Green to Yellow, Yellow to Red, and Yellow to Green-----
Foreach ($ThreeNotifiesGYYRYGi in $ThreeNotifiesGYYRYG) {
Get-AlarmDefinition -Name "$ThreeNotifiesGYYRYGi" | New-AlarmAction -Email -To ($EmailAddresses)
Get-AlarmDefinition -Name "$ThreeNotifiesGYYRYGi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
#Get-AlarmDefinition -Name "$ThreeNotifiesGYYRYGi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"
#The Yellow > Red notification is turned on my default
Get-AlarmDefinition -Name "$ThreeNotifiesGYYRYGi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
}
#
#
#
#-----NOTIFICATIONS: Puts email addresses in for Send Email From Green to Yellow and Yellow to Red-----
Foreach ($TwoNotifiesGYYRi in $TwoNotifiesGYYR) {
Get-AlarmDefinition -Name "$TwoNotifiesGYYRi" | New-AlarmAction -Email -To ($EmailAddresses)
Get-AlarmDefinition -Name "$TwoNotifiesGYYRi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
#Get-AlarmDefinition -Name "$TwoNotifiesGYYRi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"
}
#
#
#
#-----NOTIFICATIONS: Puts email addresses in for Send Email From Yellow to Red and Yellow to Green-----
Foreach ($TwoNotifiesYRYGi in $TwoNotifiesYRYG) {
Get-AlarmDefinition -Name "$TwoNotifiesYRYGi" | New-AlarmAction -Email -To ($EmailAddresses)
Get-AlarmDefinition -Name "$TwoNotifiesYRYGi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"
Get-AlarmDefinition -Name "$TwoNotifiesYRYGi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
}
#
#-----NOTIFICATIONS: Puts email addresses in for Send Email From Yellow to Red-----
Foreach ($OneNotifyYRi in $OneNotifyYR) {
Get-AlarmDefinition -Name "$OneNotifyYRi" | New-AlarmAction -Email -To ($EmailAddresses)
#Get-AlarmDefinition -Name "$OneNotifyYRi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"
}
#
#
#
#-----NOTIFICATIONS: Puts email addresses in for Send Email From Green to Yellow-----
Foreach ($OneNotifyGYi in $OneNotifyGY) {
Get-AlarmDefinition -Name "$OneNotifyGYi" | New-AlarmAction -Email -To ($EmailAddresses)
Get-AlarmDefinition -Name "$OneNotifyGYi" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
}
#
#
#
#
#-----Disconnect from vCenter-----
Disconnect-VIServer

About

Lauren Malhoit has been in the IT field for over 10 years and has acquired several data center certifications. She's currently a Technology Evangelist for Cisco focusing on ACI and Nexus 9000. She has been writing for a few years for TechRepublic, Te...

1 comments
johndball
johndball

Sweeeeeet! Saved me a lot of hassle and we all know that hassle isn't very fun.