Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 225858

Re: Script to export Alarms from VCenter to analyze.

$
0
0

Hi James,

 

Here is the new version, find the attached below.

One thing to note is the script looks for only the alarms with Action set, i.e. SNMP, SendEmail...etc

 

$output = foreach ($alarm in (Get-AlarmDefinition | Sort Name | Get-AlarmAction))

{

    $threshold = foreach ($expression in ($alarm | %{$_.AlarmDefinition.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

        }

    }  

   

    $alarm | Select-Object @{N="Alarm";E={$alarm | %{$_.AlarmDefinition.Name}}},

                           @{N="Description";E={$alarm | %{$_.AlarmDefinition.Description}}},

                           @{N="Threshold";E={[string]::Join(" // ", ($threshold))}},

                           @{N="Action";E={if ($alarm.ActionType -match "SendEmail") { "" + $alarm.ActionType + " to " + $alarm.To } else { "" + $alarm.ActionType }}}

}

    

$output | Export-Csv alarm.csv -UseCulture -NoTypeInformation

 

Sample Output:

 

AlarmDescriptionThresholdAction
Cannot connect to storageDefault alarm to monitor host connectivity to storage devicevprob.storage.connectivity.lost // vprob.storage.redundancy.lost // vprob.storage.redundancy.degraded // esx.problem.vmfs.nfs.server.disconnectSendSNMP
Exit standby errorDefault alarm to monitor if a host cannot exit standby modeExitStandbyModeFailedEvent // DrsExitStandbyModeFailedEventSendSNMP
Health status changed alarmDefault alarm to monitor changes to service and extension health statusHealthStatusChangedEventSendSNMP
Virtual Machine with SnapshotsTesting alarm to notify if someone creates a snapshot on a certain virtual machine.Warning: isAbove to 1048576 Alert: isAbove to 2097152SendEmail to alarms@test-lab.com

 

Hope this helps,

Steven.


Viewing all articles
Browse latest Browse all 225858

Trending Articles