Powercli – Create alarm actions triggers for existing alarm definitions

Here is a script i created to add the following actions for triggers on alarms:
– Send a notification email from specified alarm state and email address
– Send a notification trap from specified alarm state and email address

I recommend just testing with a single Alarm definition in CSV file to make sure it works correctly for you. Only run this once otherwise you will create duplicate triggers.

Connect-VIServer
$alarmlist = Import-CSV C:\vcenter-alarm.csv

foreach ($item in $alarmlist) {

$alarmname = $item.alarmname
$alarmstartstatus = $item.alarmstartstatus
$alarmendstatus = $item.alarmendstatus
$alarmemail = $item.alarmemail

Get-AlarmDefinition -Name $alarmname | New-AlarmAction -Email -To $alarmemail | New-AlarmActionTrigger -StartStatus $alarmstartstatus -EndStatus $alarmendstatus
Get-AlarmDefinition -Name $alarmname | New-AlarmAction -Snmp | New-AlarmActionTrigger -StartStatus $alarmstartstatus -EndStatus $alarmendstatus
}

CSV file has the following columns: (no quotes necessary for text)

alarmname alarmstartstatus alarmendstatus alarmemail

Disclaimer:
Please use this script at your own risk and test it out in your test lab first before using it in production.

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s