VMware Cloud Community
krome123
Contributor
Contributor
Jump to solution

Triggered Alarm Object

Hi,

I'm trying to create a script that sends an email with all of the daily alarms from VMware.  I have it all done but the part that finds the object that is actually in alarm.  I'm using the code below that I have seen in other similar questions, but I can't find anything in the SDK that will produce that object.  I can only get it to point to the object where it is actually defined.  Am I missing a property that will produce that or do I have to drill down to each individual object in inventory and check it for triggered alarms?

$vcenter = "vcntr01"

Connect-VIServer $vcenter

$datacenters = (Get-datacenter * | get-View)

foreach($datacenter in $datacenters){

    foreach($triggered in $datacenter.TriggeredAlarmState){

        $alarmDef = Get-View -Id $triggered.Alarm

        Write-Host "$((get-view $alarmDef.Info.entity).name)  $($alarmDef.Info.Name)"

       

    }

}

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState} | %{
 
$_.ExtensionData.triggeredAlarmState |
 
Select Time,
   
@{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},
   
@{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}}
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datacenter | where {$_.ExtensionData.triggeredAlarmState} | %{
 
$_.ExtensionData.triggeredAlarmState |
 
Select Time,
   
@{N="Entity";E={Get-View $_.Entity | Select -ExpandProperty Name}},
   
@{N="Alarm";E={Get-View $_.Alarm | Select -ExpandProperty Info | Select -ExpandProperty Name}}
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
krome123
Contributor
Contributor
Jump to solution

Yes that did it! Didn't think to use it. Thanks a bunch.

0 Kudos
sivagndl
Enthusiast
Enthusiast
Jump to solution

how to get additional info like Status(EX:- Alart or Warninig) and Vcenter Name(we connected multiple VCS).

0 Kudos
vin01
Expert
Expert
Jump to solution

This could be helpful..

#
# 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"

Regards Vineeth.K
0 Kudos