Hello,
we are testing the automatic configuration of email alerts from all 54 default alarms as of version 5.0 of the vCenter Appliance.
Since this is something that we are planning to do on all installs/upgrades it can be a time-consuming task having to manually configure each alarm defined on each vCenter so I pointed to a blog article from VMpros that seems to be discussing a similar task and that suggests using PowerCLI script to take care of that:
http://blog.vmpros.nl/2011/07/04/vmware-change-alarm-actions-with-powercli/
I have arranged the script from its original version because we don’t need to change some alarm actions to send the Alarm notifications to a different email address once a week. Instead, we will be performing a one-shot activity.
After configuring the vCenter server connection information and changing the email addresses, I have successfully tested the customized script to add email notifications to a test alarm (named “Test alarm”) to a simple action I had previously created (powering on a VM in our lab). The script added email notifications to our test alarm as expected with no errors.
Before modifying the script to add email notifications to all 54 default alarms as needed I decided to test the customized script against one of the predefined alarms (named “Host hardware power status”). While the script added email notifications to the “Host hardware power status” alarm as expected, it ended up with errors.
I just would like to make sure that our customized script does not contain script errors before using it on all installs/upgrades (any suggestion or critic is welcome).
I have pasted the resulting error from the Windows PowerShell prompt below.
Thanks and Regards,
Massimiliano
==================================================
PowerCLI D:\> .\Change_Alarm_Datacenter.ps1
Action Type Trigger
----------- -------
SendEmail ...
SendEmail ...
SendEmail ...
New-AlarmActionTrigger : 21/05/2012 16:35:11 New-AlarmActionTrigger A
specified parameter was not correct.
In D:\Change_Alarm_Datacenter.ps1:37 car:82
+ Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | New-AlarmActionTri
gger <<<< -StartStatus "Green" -EndStatus "Yellow"
+ CategoryInfo : NotSpecified: (:) [New-AlarmActionTrigger], Inva
lidArgument
+ FullyQualifiedErrorId : Client20_AlarmServiceImpl_NewAlarmActionTrigger_
ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Alarm.NewAlarmActionT
rigger
Uid : /VIServer=administrator@vcenter5:443/Alarm=Alarm-alarm-17/SendEma
ilAction=1508771755/AlarmTriggeringActionTransitionSpec=-83030421
6/
StartStatus : Green
EndStatus : Yellow
Repeat : False
AlarmAction : SendEmail
Uid : /VIServer=administrator@vcenter5:443/Alarm=Alarm-alarm-17/SendEma
ilAction=-1903891658/AlarmTriggeringActionTransitionSpec=-8303042
16/
StartStatus : Green
EndStatus : Yellow
Repeat : False
AlarmAction : SendEmail
Uid : /VIServer=administrator@vcenter5:443/Alarm=Alarm-alarm-17/SendEma
ilAction=-1765994019/AlarmTriggeringActionTransitionSpec=-8303042
16/
StartStatus : Green
EndStatus : Yellow
Repeat : False
AlarmAction : SendEmail
==================================================
Ok, I think I found the problem.
You are defining 3 actions on that alarm (3 x Email).
That means that this
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction
will return 3 objects (one for each action).
Unfortunately the New-AlarmActionTrigger cmdlet wants 1 Action object as input, not an array.
The solution is to select explictely the Action for which you want to change the trigger.
Something like this
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 0 | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 1 | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 2 | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
Watch out, the script does not remove the old triggers, so you'll end up having multiple triggers for the actions.
Use the Remove-AlarmActionTrigger first to remove all existing triggers.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Which specific alarm are you trying to update ?
What is in $actAlarm1 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I have defined it in the script I have arranged:
==================================================
==================================================
I have also attached the full script (just in case).
Thank you again for your support.
Massimiliano
Ok, I think I found the problem.
You are defining 3 actions on that alarm (3 x Email).
That means that this
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction
will return 3 objects (one for each action).
Unfortunately the New-AlarmActionTrigger cmdlet wants 1 Action object as input, not an array.
The solution is to select explictely the Action for which you want to change the trigger.
Something like this
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 0 | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 1 | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction | Select -Index 2 | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
Watch out, the script does not remove the old triggers, so you'll end up having multiple triggers for the actions.
Use the Remove-AlarmActionTrigger first to remove all existing triggers.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi there,
thank you for writing further.
I will feedback to you tomorrow morning after arranging the script as per your suggestion and testing.
I really appreciate your help.
Massimiliano
Hi there,
I did not have an opportunity to arrange the script as per your solution yet, however I would like to share a slightly different solution I found after reviewing yours.
The one thing that seemed strange to me is that while I have successfully tested the customized script to add email notifications to a test alarm (named “Test alarm”) to a simple action I had previously created (powering on a VM in our lab) with no errors, the same exact script added email notifications to the “Host hardware power status” default alarm as expected ending up with errors.
The only difference between the test alarm I had previously created and the “Host hardware power status” default alarm in vCenter 5.0 was that while the first one did not have any other action defined on it, the second one already had the default action from VMware (send SNMP).
After arranging the script as below:
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction -ActionType "SendEmail" | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction -ActionType "SendEmail" | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"
Get-AlarmDefinition -Name "$actAlarm1" | Get-AlarmAction -ActionType "SendEmail" | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"
I have been able to add email notifications to all 54 alarms as of vCenter 5.0 with no error.
Thanks and Regards,
Massimiliano
I dont suppose you'd care to share your solution? seems only fair after luc helped you out...