当前位置: 动力学知识库 > 问答 > 编程问答 >

Vmware Powecli Alarm trigger

问题描述:

I'm trying to create a PowerCLI script that for each Alarm check if it has defined a SNMP type AlarmAction and convert this AlarmAction into a email, maintaining the same configuration of the triggers.

I have written this:

$vCenter = "vcenter"

$EmailAddresses = "[email protected]"

Connect-VIServer -Server "$vCenter" -User "user" -Password "pass"

Foreach ($Alarm in Get-AlarmDefinition) {

$AlarmAction = Get-AlarmAction -AlarmDefinition $Alarm

If ( $AlarmAction.ActionType -eq "SendSNMP") {

$NewAlarmAction = New-AlarmAction -AlarmDefinition $Alarm -Email -To $EmailAddresses

#Foreach ($NewAlarmActionTrigger in Get-AlarmActionTrigger -AlarmAction $NewAlarmAction) {

# Remove-AlarmActionTrigger -AlarmActionTrigger $NewAlarmActionTrigger

#}

Foreach ($AlarmActionTrigger in Get-AlarmActionTrigger -AlarmAction $AlarmAction) {

If ($AlarmActionTrigger.Repeat) {

New-AlarmActionTrigger -AlarmAction $NewAlarmAction -StartStatus $AlarmActionTrigger.StartStatus -EndStatus $AlarmActionTrigger.EndStatus -Repeat

} else {

New-AlarmActionTrigger -AlarmAction $NewAlarmAction -StartStatus $AlarmActionTrigger.StartStatus -EndStatus $AlarmActionTrigger.EndStatus

}

}

Remove-AlarmAction $AlarmAction -Confirm:$false

}

}

Disconnect-VIServer -Server "$vCenter" -Confirm:$false

The problem is that on New-AlarmAction a new Alarm is created with at least one trigger configured (usually Yellow to Red). If I try to modify it with New-AlarmActionTrigger it will return:

New-AlarmActionTrigger A specified parameter was not correct.

If I comment out the Remove-AlarmActionTrigger block it will return:

Remove-AlarmActionTrigger You cannot remove this AlarmActionTrigger. The AlarmAction must have at least one AlarmActionTrigger.

So basically you cannot fully configure a new alarm (doesn't seem to exist a Set-AlarmActionTrigger cmdlet)

What should I do?

分享给朋友:
您可能感兴趣的文章:
随机阅读: