Martyg1987
Contributor
Contributor

Using PowerCLi to add email alerts

Hey There,

I am trying to use power cli to modify my email alerts and have come across a small issue.

This is the line which is giving me trouble

Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat

I always get an error when trying to set the yellow to red status to repeat.

I have tried green to yellow and yellow to green and they work just fine, I can also change the yellow to red in the GUI, it just wont let me do it through powerCLI?

Should I not be able to change it? I have been looking at the VMware docs all morning and cant seem to see anything which suggests I shouldnt be able to?

Thanks

Martin

0 Kudos
7 Replies
Troy_Clavell
Immortal
Immortal

0 Kudos
Ashley004
Contributor
Contributor

Hi Martin

I'm experiencing the same problem , did you get this resolved ?

Regards

Ashley

0 Kudos
LucD
Leadership
Leadership

I suspect you already have a trigger for Yellow to Red. At least that is when I can reproduce your error.

You need a Set-AlarmActionTrigger cmdlet, which doesn't exist (yet).

Try adding a trigger for another type of trigger, for example Red to Yellow.

As an alternative combine a Remove-AlarmActionTrigger with a New-AlarmActionTrigger cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Ashley004
Contributor
Contributor

Please excuse my CLI noobness

When I add and use

New-AlarmActionTrigger -StartStatus "red" -EndStatus "yellow"

no problem ,

When I try

New-AlarmActionTrigger -StartStatus "yellow" -EndStatus "red”

I get errors

0 Kudos
LucD
Leadership
Leadership

No problem, we were all noobs at one point in time :smileygrin:

The problem comes from the fact that you can't use the New-AlarmActionTrigger cmdlet to replace an existing trigger.

So in your case you probably didn't have a trigger for Red to Yellow, but you did have one for Yellow to Red.

If you execute the cmdlet again for the Red to Yellow trigger, you should get the same error.

You can check what triggers are there via the vSphere client as well.

The solution is to first check if the trigger is already present, and if yes, remove the trigger (Remove-AlarmActionTrigger), and finally add the "new" trigger (New-AlarmActionTrigger) with the updated settings.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Ashley004
Contributor
Contributor

Hi

Thanks for the help so far

Unless im doing something incorrect ( which is very possible) there seems to be a problem adding a trigger for alarms going from yellow to red with repeat.

I removed all triggers etc before trying the script again and still get the issue when trying to add yellow to red.

0 Kudos
LucD
Leadership
Leadership

I did another test, and it seems to work for me.

Before

before.png

Then I run this script

$alarmName = "Test Alarm" 
$alarm = Get-AlarmDefinition -Name $alarmName 
$action
= Get-AlarmAction -AlarmDefinition $alarm
$trigger
= Get-AlarmActionTrigger -AlarmAction $action
$newTrigger
= New-AlarmActionTrigger -AlarmAction $action -StartStatus Red -EndStatus Yellow -Repeat
Remove-AlarmActionTrigger
-AlarmActionTrigger $trigger -Confirm:$false

And the result

after.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos