Hi everybody,
I'm trying to add a new alarm action to all my vCenter alarm definitions. Nothing fancy and because I'm lazy, I tried to utilize PowerCLI for this. This is my small script:
Get-AlarmDefinition | % {
$_ | Get-AlarmAction | Remove-AlarmAction -Confirm:$false
$_ | New-AlarmAction -Email -To 'user@domain.tld' | % {
$_ | New-AlarmActionTrigger -StartStatus 'Yellow' -EndStatus 'Red' -Repeat:$false
$_ | New-AlarmActionTrigger -StartStatus 'Green' -EndStatus 'Yellow' -Repeat:$false
}
}
When I run it, the alarm action and both triggers are added. But during the add of the alarm trigger from 'Yellow' to 'Red', the following error occurs:
New-AlarmActionTrigger : 04.07.2015 16:59:25 New-AlarmActionTrigger A specified parameter was not correct.
At C:\Users\patrick\AppData\Local\Temp\bcfe38ed-7669-43dd-a588-7e88e59d70c4.ps1:4 char:8
+ $_ | New-AlarmActionTrigger -StartStatus 'Yellow' -EndStatus 'Red' -Repeat:$fa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AlarmActionTrigger], InvalidArgument
+ FullyQualifiedErrorId : Client20_AlarmServiceImpl_NewAlarmActionTrigger_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Alarm.NewAlarmActionTrigger
Unfortunately I can't figure out what parameter isn't correct. The error only occurs for 'Yellow' to 'Red'. Any idea what is wrong or what I missed?
Thanks for advice!
Strange, afaik there is no 6R2 beta at the moment.
Yes, that should work.
Perhaps you could find some clues in the vpxd.log.
Otherwise use Onyx to check what is really being passed to the methods.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Your script seems to be working for me (vSphere 6 & PowerCLI 6R1).
Could be something in the original definition of the alarm.
Perhaps share what is in an original alarm, something like this
$alarm = Get-AlarmDefinition -Name AnAlarm
$alarm | Select *
$action = Get-AlarmAction -AlarmDefinition $alarm
$action | Select *
Get-AlarmActionTrigger -AlarmAction $action | Select *
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
thanks for your reply. This is the output of your script:
WARNING: PowerCLI scripts should not use the 'Client' property. The property will be removed in a future release.
Entity : Datacenters
Description : Default alarm to monitor host connectivity to storage device
Enabled : True
Name : Cannot connect to storage
ExtensionData : VMware.Vim.Alarm
ActionRepeatMinutes : -1
Id : Alarm-alarm-25
Uid : /VIServer=lab\p.terlisten@vcsa1.lab.local:443/Alarm=Alarm-alarm-25/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
Body :
Cc : {}
To : {user@domain.tld}
Subject :
ActionType : SendEmail
AlarmDefinition : Cannot connect to storage
Trigger : {Yellow -> Red (Once), Green -> Yellow (Once)}
Uid : /VIServer=lab\patrick@vcsa1.lab.local:443/Alarm=Alarm-alarm-25/SendEmailAction=1949811328/
AlarmVersion : 18
Client :
Uid : /VIServer=lab\patrick@vcsa1.lab.local:443/Alarm=Alarm-alarm-25/SendEmailAction=1949811328/AlarmTriggeringActionTransitionSpe
c=1062223280/
StartStatus : Yellow
EndStatus : Red
Repeat : False
AlarmAction : SendEmail
AlarmVersion : 18
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
Uid : /VIServer=lab\p.terlisten@vcsa1.lab.local:443/Alarm=Alarm-alarm-25/SendEmailAction=1949811328/AlarmTriggeringActionTransitionSpe
c=-830304216/
StartStatus : Green
EndStatus : Yellow
Repeat : False
AlarmAction : SendEmail
AlarmVersion : 18
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
I double checked my PowerCLI version and I was using PowerCLI 6.0 R2 beta. I downgraded to PowerCLI 6.0 R1, but the error persists.
Strange, which buildnumber did you see for that beta ?
Can you do a Get-PowerCLIVersion ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
I've tested a lot in the last days and during this tests, I downgraded to R1. Unfortunately I didn't recorded the build of the beta.
But from your point of view this must work? Then it must be something in my lab...
Strange, afaik there is no 6R2 beta at the moment.
Yes, that should work.
Perhaps you could find some clues in the vpxd.log.
Otherwise use Onyx to check what is really being passed to the methods.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your help!
Hi,
I found a Snapshot with the PowerCLI release I was running before the downgrade.
PowerCLI 6.0 Release 2 Beta build 1912167
I am getting the same error trying to set either of the following vCenter 6.7 U1 alarms. The alarms names are identical except for the case on the A/a of alarm.
Name: vSAN health alarm 'Network adapter is VMware certified'
Description: Default alarm to monitor changes for the health test 'Network adapter is VMware certified'
Name:vSAN Health Alarm 'Network adapter is VMware certified'
Description: Default alarm to monitor changes for the online health test 'Network adapter is VMware certified'
The command
Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat | Out-Null
Error given for both is:
New-AlarmActionTrigger : 08/12/2018 14:18:53 New-AlarmActionTrigger A specified parameter was not correct:
At C:\Users\Administrator\OneDrive\My PowerShell\VMware\Set vCenter Alarms\Set-vCenterAlarmEmails.ps1:96 char:101
+ ... SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AlarmActionTrigger], InvalidArgument
+ FullyQualifiedErrorId : Client20_AlarmServiceImpl_NewAlarmActionTrigger_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Alarm.NewAlarmActionTrigger
I am using:
PSVersion 5.1.14409.1018
VMware.PowerCLI 11.0.0.10380590
vCenter 6.7 U1 vCenter Appliance 6.7 U1 (6.7.0.20000)
Any ideas
Thanks
M
You need to start with an alarm definition.
Something like this
Get-AlarmDefinition -Name 'MyAlarm' |
Get-AlarmAction -ActionType SendEmail |
New-AlarmActionTrigger -StartStatus Yellow -EndStatus Red -Repeat
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Thanks for the reply.
Apologies, I am providing the alarm definition, I just didn't copy the whole of the PS script into the post.
These two alarms are the only ones out of the 260+ alarms available in vCenter 6.7u1 that are failing to set a 'Yellow to Red' trigger.
Pretty sure its not the script, but something more fundamental regarding these two alarms themselves.
Cheers
Martin
Would you mind sharing at the least the lines of code involving the alarms?
Are you handling both alarms at the same time or separate?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
The full script & alarm .csv file are here: GitHub - mc1903/vCenter-67-Alarms: Configure vSphere vCenter v6.7 Email Alarm Actions via Powershell
The alarms in question are on lines 169 & 170 of the .csv file.
Thanks
Martin
The Alarm related cmdlets are too limited to change those kind of settings.
And indeed, these 2 alarms are rather strange.
One with a green->yellow (and no repeat) and the other with yellow->red (and repeat).
The only way I was able to align them was to use the API method.
Something like this
$alarmMgr = Get-View AlarmManager
$si = Get-View ServiceInstance
Get-View -Id ($alarmMgr.GetAlarm($si.Content.RootFolder)) |
where{$_.Info.Name -match "vSAN Health [Aa]larm 'Network adapter is VMware certified'"} |
ForEach-Object -Process {
$spec = [VMware.Vim.AlarmSpec]$_.Info
$spec.Action.Action[0].TransitionSpecs[0].StartState = [VMware.Vim.ManagedEntityStatus]::yellow
$spec.Action.Action[0].TransitionSpecs[0].FinalState = [VMware.Vim.ManagedEntityStatus]::red
$spec.Action.Action[0].TransitionSpecs[0].Repeats = $true
$_.ReconfigureAlarm($spec)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for taking the time to look at this LucD,
I won't pretend to understand your code (you are many many leagues ahead of where I am in my Powershell journey), but I will have a go at integrating it into my script in the future.
For the time being tho, I will ignore both alarms and look to test them again when the next patch/update of vCenter is released.
Cheers,
Martin