How can I get triggered alarms using PowerCLI?
11,668
Solution 1
To find all vmhosts with alarm status = "red", I expanded on this.
#
# Find all hosts with triggered alarms in "Red" state
#
$esx_all = Get-VMHost | Get-View
$Report=@()
foreach ($esx in $esx_all){
foreach($triggered in $esx.TriggeredAlarmState){
If ($triggered.OverallStatus -like "red" ){
$lineitem={} | Select Name, AlarmInfo
$alarmDef = Get-View -Id $triggered.Alarm
$lineitem.Name = $esx.Name
$lineitem.AlarmInfo = $alarmDef.Info.Name
$Report+=$lineitem
}
}
}
$Report |Sort Name | export-csv "c:\temp\ESX-Host-Red-Alarms.csv" -notypeinformation -useculture
Invoke-item "c:\temp\ESX-Host-Red-Alarms.csv"
Solution 2
this is what i use.
$esx = Get-VMHost $vmhost | Get-View
foreach($triggered in $esx.TriggeredAlarmState){
$alarmDef = Get-View -Id $triggered.Alarm
Write-Host $alarmDef.Info.Name
}
Related videos on Youtube
Comments
-
Andrew J. Brehm over 1 year
In vSphere Client on a VM host in the Alarms tab there is a view of Triggered Alarms.
How can I get those alarms using PowerCLI?
-
Andrew J. Brehm almost 11 yearsI had tried that but it never returned anything at all, while the "Triggered Alarms" view in vSPhere Client showed my triggered alarm. (I created a triggered alarm based on a VM being used more than 1% CPU over 30 seconds as a test alarm.)
-
johnshen64 almost 11 yearsYou may need to look at the vm view in that case. I am not sure if vm alarms are included in the vmhost view.
-
Falcon Momot over 10 yearsYou can format your code as it is formatted now (I've done it for you) by indenting with 4 spaces.