Quickly configuring vCenter alarms using PowerCLI

To quickly configure all vCenter alarms to send an email, use this snippet:

Get-AlarmDefinition | New-AlarmAction -Email -To '[email protected]'

Once that is in place, set up an AlarmActionTrigger to send an email when the monitored item moves from green to yellow. The default AlarmAction created earlier already contains a setting for moving from yellow to red:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like '[email protected]'} | New-AlarmActionTrigger -startstatus 'Green' -EndStatus 'Yellow'

To have the alarm action repeat, use the -Repeat flag on the New-AlarmActionTrigger.

To add other transitions, use the New-AlarmActionTrigger and change the -StartStatus and -EndStatus to the desired transition. For example, -StartStatus ‘Red’ -EndStatus ‘Yellow’ will set the alarm to notify “Once” when moving from Red down to Yellow.

To see all Alarms configured to send to a certain email address along with triggers:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | Where-Object {$_.To -like '[email protected]'} | Select AlarmDefinition,To,Trigger

To remove all SendEmail AlarmActions for a particular email address:

Get-AlarmDefinition | Get-AlarmAction -ActionType SendEmail | where-object {$_.To -like '[email protected]'} | Remove-AlarmAction

Further information at https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.ug.doc%2FGUID-3758D090-C799-4BA0-8F6C-1C2E7A055D1B.html

One thought on “Quickly configuring vCenter alarms using PowerCLI

Comments are closed.