Automation

 View Only

 Create a script to scan all the alerts/critical event/ alarms on the vcenter

gauravmriu's profile image
gauravmriu posted Jun 23, 2024 10:41 PM

Hi All,

I require a script (Not Python bases) so that this can scan all the critical alerts/ warnings/ high alarms on the vCenter and capture/save into a excel or a text file.

FYI.. vCener Server: 7.0.3

LucD's profile image
LucD

You could do something like this.

Note that triggered Alarms on the VCSA are listed on the Folder named Datacenters.

$si = Get-View ServiceInstance
$viewMgr = Get-View -Id $si.Content.ViewManager
$contView = $viewMgr.CreateContainerView($si.Content.RootFolder, $null, $true)
$contViewObj = Get-View -Id $contView

$si.Content.RootFolder, (Get-View -Id $contViewObj.View | Select-Object -ExpandProperty MoRef) |
ForEach-Object -Process {
  Get-View -Id $_ -Property Name, TriggeredAlarmState -PipelineVariable object |
  ForEach-Object -Process {
    $object.TriggeredAlarmState |
    ForEach-Object -Process {
      $alarm = Get-View -Id $_.Alarm
      New-Object -TypeName PSObject -Property ([ordered]@{
        Entity = $object.Name
        EntityType = $object.GetType().Name
        Alarm = $alarm.Info.Name
        Created = $_.Time
        State = $_.OverallStatus
        Acknowledged = $_.Acknowledged
      })
    }
  }
} | Export-Csv -Path .\Alarm-report.csv -UseCulture