简体   繁体   中英

How can I configure vCenter Alarm by Cluster with PowerCLI

I have a code to configure the vcenter alarm, however, I would like to create a alarm in per Cluster level.

Please advise me any direction I can go to.

Here is the code, but it won't work

$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"
        }
    }
}

Try changing to the below code, basically by default when creating a trigger yellow to red is set to "Once" this needs to be removed before being added back in.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM