VMware Cloud Community
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

Configured Alarms list per VC, DC, Cluster, Host, VM Level

Hi All, i am looking for an option to get the "Configured Alarms list per VC, DC, Cluster, Host, VM Level" with the powercli script.,

and another script which is to pull all the triggered script in the infra.

Regards, Satheesh
1 Solution

Accepted Solutions
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

hi LuCD,

i have added the below content and i am able to get it.

$alarm = $alarmname | Get-AlarmAction

      $threshold = foreach ($expression in ($alarmname | %{$_.ExtensionData.Info.Expression.Expression})){

        if ($expression.EventTypeId -or ($expression | %{$_.Expression})){

            if ($expression.Status) {

            switch ($expression.Status) { "red" {$status = "Alert"} "yellow" {$status = "Warning"} "green" {$status = "Normal"}}; "" + $status + ": " + $expression.EventTypeId }

             else { $expression.EventTypeId }        

        }

        elseif ($expression.EventType){

            $expression.EventType

        }

   if ($expression.Yellow -and $expression.Red){

            if (!$expression.Yellow) { $warning = "Warning: " + $expression.Operator } else { $warning = "Warning: " + $expression.Operator + " to " + $expression.Yellow };

            if (!$expression.Red) { $alert = "Alert: " + $expression.Operator } else { $alert = "Alert: " + $expression.Operator + " to " + $expression.Red };

            $warning + " " + $alert

        }

    } 

if ($alarm.ActionType -match "SendEmail") {

$action =  "" + $alarm.ActionType + " to " + $alarm.To

}

else {

$action = "" + $alarm.ActionType }

i am able to get the output like what i expected.

Alarm AlarmType Description Enabled threshold Action

VMware HTTP Reverse Proxy Service Health Alarm. Default alarm that monitors the health status of HTTP Reverse Proxy Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vSphere UI Health Alarm vSphere UI service alarm to monitor health status TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vCenter Stats Monitor Service Health Alarm. Default alarm that monitors the health status of vCenter Stats Monitor Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vCenter HA Service Health Alarm. Default alarm that monitors the health status of vCenter HA Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

Regards, Satheesh

View solution in original post

14 Replies
LucD
Leadership
Leadership
Jump to solution

What do you mean with "triggered scrip in the infra"?

Or do you mean triggered alarms in the infra?

And if yes, over which time frame?


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

Reply
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

please find the request as below.

1. Alarms configured in my infra under alarm definition( object VM\Host\vcenter\DC\Cluster\Datastore) - this is for audit purpose (we will do the modification at later point)

2. current Triggered alarms in the infra.(as our infra is with 27vcenter server, each vc have more than 80 alarms) so want to collect the report of current triggred list.

Regards, Satheesh
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

1. Defined alarms

foreach($vc in $global:defaultVIservers){

   foreach($alarm in Get-AlarmDefinition -Server $vc){

   $obj = [ordered]@{

  vCenter = $vc.Name

  Datacenter = ''

  Cluster = ''

  ResourcePool = ''

  VMHost = ''

  Folder = ''

  VM = ''

  Alarm = $alarm.Name

  Description = $alarm.Description

  Enabled = $alarm.Enabled

  }

   switch($alarm.Entity.GetType().Name){

   'DatacenterImpl' {

   $obj.Datacenter = $alarm.Entity.Name

  }

   'ClusterImpl' {

   $obj.Cluster = $alarm.Entity.Name

   $obj.Datacenter = (Get-Datacenter -Cluster $alarm.Entity.Name).Name

  }

   'VMHostImpl' {

   $obj.VMHost = $alarm.Entity.Name

   $obj.Cluster = (Get-Cluster -VMHost $alarm.Entity.Name).Name

  }

   'ResourcePoolImpl' {

   $obj.ResourcePool = $alarm.Entity.Name

   $obj.Cluster = (Get-Cluster | where{(Get-ResourcePool -Location $_).Name -eq $alarm.Entity.Name}).Name

   $obj.Datacenter = Get-Datacenter -Cluster $obj.Cluster

  }

   'FolderImpl' {

   if($alarm.Entity.Name -ne 'Datacenters'){

   $obj.Folder = $alarm.Entity.Name

   $obj.Datacenter = (Get-Folder -Name $alarm.Entity.Name | Get-Datacenter).Name

  }

  }

   'VirtualMachineImpl' {

   $obj.VM = $alarm.Entity.Name

   $obj.VMHost = (Get-VMHost -VM $alarm.Entity.Name).Name

   $obj.Cluster = (Get-Cluster -VM $alarm.Entity.Name).Name

   $obj.Datacenter = (Get-Datacenter -Cluster $obj.Cluster).Name

  }

  Default {

   Write-Host "$_ unknown type"

  }

  }

   New-Object -TypeName PSObject -Property $obj

  }

}

2. Triggered alarms

foreach($vc in $global:defaultVIservers){

   $si = Get-View ServiceInstance -Server $vc

   $root = Get-View -Id $si.Content.RootFolder

   $root.TriggeredAlarmState |

  Select @{N='vCenter';E={$vc.Name}},

  @{N='Entity';E={(Get-View -id $_.Entity -Property Name).Name}},

  Time,OverallStatus,Acknowledged,

  @{N='Alarm';E={(Get-View -Id $_.Alarm -Property Info).Info.Name}}


}


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

satheeshsatz
Enthusiast
Enthusiast
Jump to solution

Hi LuCd,

when execute the same, i am not getting the output properly

i am getting most of the values are empty, can you please help on this?

======================

vCenter      : EIVC50XXXXXXXXX

Datacenter   :

Cluster      :

ResourcePool :

VMHost       :

Folder       :

VM           :

Alarm        : VTS - ESX CPU UTILIZATION

Description  : Alarm to monitor the host CPU utilization

Enabled      : True

vCenter      : EIVC50XXXXXXXXX

Datacenter   :

Cluster      :

ResourcePool :

VMHost       :

Folder       :

VM           :

Alarm        : VTS - ESX MEMORY UTILIZATION

Description  : Alarm to monitor ESXi memory utilization

Enabled      : True

vCenter      : EIVC50XXXXXXXXX

Datacenter   :

Cluster      :

ResourcePool :

VMHost       :

Folder       :

VM           :

Alarm        : VTS - NETOWRK HEALTH

Description  : Alarm to monitor the redundancy of the network paths

Enabled      : True

vCenter      : EIVC50XXXXXXXXX

Datacenter   :

Cluster      :

ResourcePool :

VMHost       :

Folder       :

VM           :

Alarm        : VTS - STORAGE HEALTH

Description  : Alarm to monitor host connectivity to storage device

Enabled      : True

===================

Regards, Satheesh
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

On which inventory object did you define those alarms?

On the vCenter?


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

Reply
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

in our infra, we used to set alarms on vcenter level with the monitoring type as host\vm\vcenter\cluster(it is monitoring type in gui).

so how can i export with respective values

Regards, Satheesh
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In this variation I have added the AlarmType property, this indicates for which kind of object the alarm is set.

The empty Datacenter, Cluster, ResourcePool, VMHost... indicate that the Alarm was defined on the vCenter root, the hidden Datacenters folder.

foreach ($vc in $global:defaultVIservers) {

   foreach ($alarm in Get-AlarmDefinition -Server $vc) {

   $obj = [ordered]@{

  vCenter = $vc.Name

  Datacenter = ''

  Cluster = ''

  ResourcePool = ''

  VMHost = ''

  Folder = ''

  VM = ''

  Alarm = $alarm.Name

  AlarmType = $alarm.ExtensionData.Info.Expression.Expression.Type +

   $alarm.ExtensionData.Info.Expression.Expression.ObjectType +

   $alarm.ExtensionData.Info.Expression.Expression.Expression.ObjectType +

   $alarm.ExtensionData.Info.Expression.Expression.Expression.Type |

  Sort-Object -Unique

  Description = $alarm.Description

  Enabled = $alarm.Enabled

  }

   switch ($alarm.Entity.GetType().Name) {

   'DatacenterImpl' {

   $obj.Datacenter = $alarm.Entity.Name

  }

   'ClusterImpl' {

   $obj.Cluster = $alarm.Entity.Name

   $obj.Datacenter = (Get-Datacenter -Cluster $alarm.Entity.Name).Name

  }

   'VMHostImpl' {

   $obj.VMHost = $alarm.Entity.Name

   $obj.Cluster = (Get-Cluster -VMHost $alarm.Entity.Name).Name

  }

   'ResourcePoolImpl' {

   $obj.ResourcePool = $alarm.Entity.Name

   $obj.Cluster = (Get-Cluster | where {(Get-ResourcePool -Location $_).Name -eq $alarm.Entity.Name}).Name

   $obj.Datacenter = Get-Datacenter -Cluster $obj.Cluster

  }

   'FolderImpl' {

   if ($alarm.Entity.Name -ne 'Datacenters') {

   $obj.Folder = $alarm.Entity.Name

   $obj.Datacenter = (Get-Folder -Name $alarm.Entity.Name | Get-Datacenter).Name

  }

  }

   'VirtualMachineImpl' {

   $obj.VM = $alarm.Entity.Name

   $obj.VMHost = (Get-VMHost -VM $alarm.Entity.Name).Name

   $obj.Cluster = (Get-Cluster -VM $alarm.Entity.Name).Name

   $obj.Datacenter = (Get-Datacenter -Cluster $obj.Cluster).Name

  }

  Default {

  Write-Host "$_ unknown type"

  }

  }

  New-Object -TypeName PSObject -Property $obj

  }

}


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

satheeshsatz
Enthusiast
Enthusiast
Jump to solution

for the same alerts, is it possible to get threshold details as well per alarm?
Regards, Satheesh
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

How do you plan to display that in the output?

Especially if an Alarm has multiple trigger expressions.


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

Reply
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

i wound like to get output as csv file only like we got from existing.

1. All the threshold valued per alarm in a single table.(seperate lines in same table as array)

2. All the alarm actions per alarm in single table(send email: send trap along with details)

Regards, Satheesh
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did I get that right?
You want a separate CSV file for the triggers and another one for the actions for each alarm?

That will produce an awful lot of CSV files.


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

Reply
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

Hi LuCD,

Nope, i meant to collect the data on same csv per alarm in the same row like below.

Alarm, AlarmType, Description, vCentername, Threshold, Trigger Action

Ofcourse, threshold & Triggeraction will have more lines per alarm as it will have many condtion.

Regards, Satheesh
Reply
0 Kudos
satheeshsatz
Enthusiast
Enthusiast
Jump to solution

hi LuCD,

i have added the below content and i am able to get it.

$alarm = $alarmname | Get-AlarmAction

      $threshold = foreach ($expression in ($alarmname | %{$_.ExtensionData.Info.Expression.Expression})){

        if ($expression.EventTypeId -or ($expression | %{$_.Expression})){

            if ($expression.Status) {

            switch ($expression.Status) { "red" {$status = "Alert"} "yellow" {$status = "Warning"} "green" {$status = "Normal"}}; "" + $status + ": " + $expression.EventTypeId }

             else { $expression.EventTypeId }        

        }

        elseif ($expression.EventType){

            $expression.EventType

        }

   if ($expression.Yellow -and $expression.Red){

            if (!$expression.Yellow) { $warning = "Warning: " + $expression.Operator } else { $warning = "Warning: " + $expression.Operator + " to " + $expression.Yellow };

            if (!$expression.Red) { $alert = "Alert: " + $expression.Operator } else { $alert = "Alert: " + $expression.Operator + " to " + $expression.Red };

            $warning + " " + $alert

        }

    } 

if ($alarm.ActionType -match "SendEmail") {

$action =  "" + $alarm.ActionType + " to " + $alarm.To

}

else {

$action = "" + $alarm.ActionType }

i am able to get the output like what i expected.

Alarm AlarmType Description Enabled threshold Action

VMware HTTP Reverse Proxy Service Health Alarm. Default alarm that monitors the health status of HTTP Reverse Proxy Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vSphere UI Health Alarm vSphere UI service alarm to monitor health status TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vCenter Stats Monitor Service Health Alarm. Default alarm that monitors the health status of vCenter Stats Monitor Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

vCenter HA Service Health Alarm. Default alarm that monitors the health status of vCenter HA Service. TRUE "Normal: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Warning: vim.event.HealthStatusChangedEvent

Alert: vim.event.HealthStatusChangedEvent" SendSNMP

Regards, Satheesh
mahesh123413
Contributor
Contributor
Jump to solution

Hello sateesh,

can you give me full script of this in a text file.

Also can you let me know how to pull to excel.

Reply
0 Kudos