Using PowerCLI to Configure vCenter Alarm Notifications in vSphere 5.1
I’ve been playing with PowerCLI a little bit recently. It really is a nice tool for automating things in your vCenter environment. If you don’t how to use VMware PowerCLI check out this page to get started. The following script will categorize each vCenter alarm according to the trigger. You can cut and paste any alarm into the different categories depending on when or if you’d like to be notified.
This script also uses the alarms from the vCenter Web Client (version 5.1) so it has alarms such as “vSphere Distributed Switch MTU matched status” which checks to make sure the MTU settings on the Virtual Distributed switch are the same as on the physical port it’s connected to.
Note: Please keep in mind your vCenter may have other alarms depending on your hardware and drivers. This is just an example of how to save time setting up vCenter alarms in multiple sites or when email addresses change. Please read through the script and test it before implementing it in a production environment.
vCenterAlarmNotificationChanges.ps1:
#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.1 #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 in vCenter 5.1----- $vCenterAlarms= "Cannot connect to storage",` "Cannot find vSphere HA master agent",` "Datastore capability alarm",` "Datastore cluster is out of space",` "Datastore is in multiple datacenters",` "Datastore usage on disk",` "Exit standby error",` "Health status changed alarm",` "Health status monitoring",` "Host Baseboard Management Controller Status",` "Host battery status",` "Host connection and power state",` "Host connection failure",` "Host CPU usage",` "Host error",` "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 capacity monitoring",` "License error",` "License inventory monitoring",` "License user threshold monitoring",` "Migration error",` "Network connectivity lost",` "Network uplink redundancy degraded",` “Network uplink redundancy lost”,` “No compatible host for Secondary VM”,` “Pre-4.1 host connected to SIOC-enabled datastore”,` “SRM Consistency Group Violation”,` “Status of other host hardware objects”,` “Storage DRS is not supported on Host”,` “Storage DRS recommendation”,` “The host license edition is not compatible with the vCenter Server license edition”,` “Thin-provisioned volume capacity threshold exceeded”,` “Timed out starting Secondary VM”,` “Unmanaged workload detected on SIOC-enabled datastore”,` “Virtual machine Consolidation Needed status”,` “Virtual machine cpu usage”,` “Virtual machine error”,` “Virtual machine Fault Tolerance state changed”,` “Virtual Machine Fault Tolerance vLockStep interval Status Changed”,` “Virtual machine memory usage”,` “VMKernel NIC not configured correctly”,` “vSphere Distributed Switch MTU matched status”,` “vSphere Distributed Switch MTU supported status”,` “vSphere Distributed Switch teaming matched status”,` “vSphere Distributed Switch vlan trunked status”,` “vSphere HA failover in progress”,` “vSphere HA host status”,` “vSphere HA virtual machine failover failed”,` “vSphere HA virtual machine monitoring action”,` “vSphere HA virtual machine monitoring error” # # # #-----Alarm notifications Send Email From Green to Yellow, Yellow to Red, and Yellow to Green----- $ThreeNotifiesGYYRYG = “vSphere HA virtual machine monitoring action”,` “vSphere HA virtual machine monitoring error” # # # #-----Alarm notifications Send Email From Green to Yellow and Yellow to Red----- $TwoNotifiesGYYR = “Pre-4.1 host connected to SIOC-enabled datastore”,` “SRM Consistency Group Violation”,` “Status of other host hardware objects”,` “Storage DRS is not supported on Host”,` “Storage DRS recommendation”,` # # # #-----Alarm notifications Send Email From Yellow to Red and Yellow to Green----- $TwoNotifiesYRYG = “VMKernel NIC not configured correctly”,` “vSphere Distributed Switch MTU matched status”,` “vSphere Distributed Switch MTU supported status”,` “vSphere Distributed Switch teaming matched status”,` “vSphere Distributed Switch vlan trunked status”,` “vSphere HA failover in progress”,` “vSphere HA host status” # # # #-----Alarm notifications Send Email From Yellow to Red----- $OneNotifyYR = "Cannot connect to storage",` "Cannot find vSphere HA master agent",` "Datastore capability alarm",` "Datastore cluster is out of space",` "Datastore is in multiple datacenters",` "Datastore usage on disk",` "Exit standby error",` "Health status changed alarm",` "Health status monitoring",` "Host Baseboard Management Controller Status",` "Host battery status",` "Host connection and power state",` "Host connection failure",` "Host CPU usage" # # # #-----Send a notification trap From Yellow to Red----- $NotifyTrapYR = "Host error",` "Host hardware fan status",` "Host hardware power status",` "Host hardware system board status",` "Host hardware temperature status" # # # #-----No Alarm Notifications----- $NoAlarms = "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 capacity monitoring",` "License error",` "License inventory monitoring",` "License user threshold monitoring" # # # #-----CLEAN UP: Remove current emails set in Alarm Actions----- Foreach ($Alarm in $vCenterAlarms) { 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
Submit a Comment