如何使用PowerCLI按群集配置vCenter警报

时间:2015-12-29 07:19:14

标签: vmware pow powercli

我有一个配置vcenter警报的代码,但是,我想在每个群集级别创建一个警报。

请告诉我任何我可以去的方向。

以下是代码,但不起作用

$MinutesToRepeat = "10"
$alarms = @("Testing")

$cluster = Get-Cluster "Prod Cluster"
foreach ($alarm in $alarms) {
    Set-AlarmDefinition -Name $alarm | %{
        $_ | Set-AlarmDefinition -ActionRepeatMinutes $MinutesToRepeat;  
        $_ | Get-AlarmAction -ActionType "SendEmail" | Remove-AlarmAction -Confirm:$false 
        $_ | New-AlarmAction -Email -To $AdminEmail | %{
            $_ | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow" 
            $_ | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat
            $_ | New-AlarmActionTrigger -StartStatus 'Red' -EndStatus 'Yellow'
            $_ | New-AlarmActionTrigger -StartStatus 'Yellow' -EndStatus "Green"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试更改为以下代码,基本上默认情况下,创建触发器黄色到红色时设置为“一次”,这需要在重新添加之前删除。

foreach ($alarm in $alarms) {
    Set-AlarmDefinition -Name $alarm -AlarmDefinition $alarm -ActionRepeatMinutes $MinutesToRepeat | %{
        $_ | Get-AlarmAction -ActionType "SendEmail" | Remove-AlarmAction -Confirm:$false 
        $_ | New-AlarmAction -Email -To $AdminEmail | %{
            $_ | New-AlarmActionTrigger -StartStatus Green -EndStatus Yellow 
            $_ | New-AlarmActionTrigger -StartStatus Red -EndStatus Yellow
            $_ | New-AlarmActionTrigger -StartStatus Yellow -EndStatus Green
        }

    }
    $AlarmAction = Get-Alarmdefinition -Name $alarm | Get-AlarmAction -ActionType 'SendEmail'
    $AlarmAction.Trigger | Where {($_.StartStatus -eq 'Yellow') -And ($_.EndStatus -eq 'Red')} | Remove-AlarmActionTrigger -Confirm:$False
    $AlarmAction | New-AlarmActionTrigger -StartStatus Yellow -EndStatus Red -Repeat
}