VMware Cloud Community
JMCELHINEY
Contributor
Contributor
Jump to solution

Script to export Alarms from VCenter to analyze.

Does anyone know of a script, or how to script an exportable report of your alarms that are being used in your Vcenter?

Need to know what thresholds are being set.

Is it emailed or SMNP as an example.

Please help.

James

1 Solution

Accepted Solutions
ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi James,

Glad it helped Smiley Happy

Please select my comment as answered then people can use it!

-S

View solution in original post

Reply
0 Kudos
12 Replies
ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi James,

Please try the following (assuming you are connected to vCenter server via PowerCLI):

$output = foreach ($alarm in Get-AlarmAction) { $alarm | Select-Object @{N="Alarm";E={$_.AlarmDefinition}}, @{N="Action Type";E={$_.ActionType}}, @{N="Trigger";E={[string]::Joi

n(",",($_.Trigger))}} }

$output | Export-CSV "C:\alarm.csv"

Modify the bold and italic to change the output path.

Sample Output:

"Alarm","Action Type","Trigger"

"Timed out starting Secondary VM","SendSNMP","Yellow -> Red (Repeat)"

"No compatible host for Secondary VM","SendSNMP","Yellow -> Red (Repeat)"

Hope this helps,

Steven.

JMCELHINEY
Contributor
Contributor
Jump to solution

Thanks for the reply and information. I will give this a try and let you know.

~James

Reply
0 Kudos
JMCELHINEY
Contributor
Contributor
Jump to solution

Hey Steven,

This was great, but I'm also looking to pull the triggers like % and the Actions like email addresses.

In short I'm try to export the alarms from our current vcenters to see what alarms are set up, with what triggers and who and how are they being notified.

example:

Datastore usage on disk     is above 75% warning and 85% alert and is sending an email to me@me.com

Thanks for the reply and assistance, James

Reply
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

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.

JMCELHINEY
Contributor
Contributor
Jump to solution

Steven,

Just wanted to say thanks, this is exactly what I was looking for and you just made reviewing and examing these so much better and eaiser. You should post this so that other's can use it.

YOU ROCK!!

James

ssbkang
Enthusiast
Enthusiast
Jump to solution

Hi James,

Glad it helped Smiley Happy

Please select my comment as answered then people can use it!

-S

Reply
0 Kudos
Bryno
Contributor
Contributor
Jump to solution

This is handy but I would like to get all alarm definitions regardless of whether or not an action is configured. Can someone assist with how I would modify this ps1 to get all alarms?

Thank you,

Bryan Oser

Reply
0 Kudos
krktech
Contributor
Contributor
Jump to solution

Steven,

Thank you, exactly what I was looking for.

Kevin

Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Thanks ssbkang‌ for the great script.

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
enich
Contributor
Contributor
Jump to solution

Hello all! Long time reader, first time poster :-). This script is awesome! Now, does anybody know how to take this exported CSV and bring it in to new vCenters?

Reply
0 Kudos
Prakas
Enthusiast
Enthusiast
Jump to solution

Hi enrich - VMware KB - VMware KB: Restoring and copying vCenter Server alarms gives a nice way of doing this

Reply
0 Kudos
idatb
Contributor
Contributor
Jump to solution

Quick Edit:

Get-AlarmDefinition | sort name | select-object name | export-csv alarm.csv <-- this did what i needed... Thanks

how would i alter this to export all alarms? im modifying a script to add alarms actions and i need the Alarm names to set  them. Your script can pull active alarms but i need to get everything so i can add to this script.

$user="USERNAME"

$pass="PASSWORD"

$vCenterServer="FQDN"

$MailtoAddresses= "EMAIL ADDRESS"

#----Connect to the vCenter Server

Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null

$sessionManager = Get-View -Id $global:DefaultVIServer.ExtensionData.Content.SessionManager

$sessionManager.SetLocale(“en-US”)

#----These Alarms will send a single email message and not repeat ----

$LowPriorityAlarms="Timed out starting Secondary VM",`

"No compatible host for Secondary VM",`

"Virtual Machine Fault Tolerance vLockStep interval Status Changed",`

"Migration error",`

"Exit standby error",`

"License error",`

"Virtual machine Fault Tolerance state changed",`

"VMKernel NIC not configured correctly",`

"Unmanaged workload detected on SIOC-enabled datastore",`

"Host IPMI System Event Log status",`

"Host Baseboard Management Controller status",`

"License user threshold monitoring",`

"Datastore capability alarm",`

"Storage DRS recommendation",`

"Storage DRS is not supported on Host.",`

"Datastore is in multiple datacenters",`

"Insufficient vSphere HA failover resources",`

"License capacity monitoring",`

"Pre-4.1 host connected to SIOC-enabled datastore",`

"Virtual machine cpu usage",`

"Virtual machine memory usage",`

"License inventory monitoring"

#----These Alarms will repeat every 24 hours----

$MediumPriorityAlarms=`

"Virtual machine error",`

"Health status changed alarm",`

"Host cpu usage",`

"Health status monitoring",`

"Host memory usage",`

"Cannot find vSphere HA master agent",`

"vSphere HA host status",`

"Host service console swap rates",`

"vSphere HA virtual machine monitoring action",`

"vSphere HA virtual machine monitoring error"

#----These Alarms will repeat every 2 hours----

$HighPriorityAlarms=`

"Host connection and power state",`

"Host processor status",`

"Host memory status",`

"Host hardware fan status",`

"Host hardware voltage",`

"Host hardware temperature status",`

"Host hardware power status",`

"Host hardware system board status",`

"Host battery status",`

"Status of other host hardware objects",`

"Host storage status",`

"Host error",`

"Host connection failure",`

"Cannot connect to storage",`

"Network connectivity lost",`

"Network uplink redundancy lost",`

"Network uplink redundancy degraded",`

"Thin-provisioned volume capacity threshold exceeded.",`

"Datastore cluster is out of space",`

"vSphere HA failover in progress",`

"vSphere HA virtual machine failover failed",`

"Datastore usage on disk"

#---Set Alarm Action for Low Priority Alarms---

Foreach ($LowPriorityAlarm in $LowPriorityAlarms) {

    Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false

    Get-AlarmDefinition -Name "$LowPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)

    Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"

    #Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red"  # This ActionTrigger is enabled by default.

    Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"

    Get-AlarmDefinition -Name "$LowPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"

}

#---Set Alarm Action for Medium Priority Alarms---

Foreach ($MediumPriorityAlarm in $MediumPriorityAlarms) {

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false

    Set-AlarmDefinition "$MediumPriorityAlarm" -ActionRepeatMinutes (60 * 24) # 24 Hours

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | Get-AlarmActionTrigger | Select -First 1 | Remove-AlarmActionTrigger -Confirm:$false

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"

    Get-AlarmDefinition -Name "$MediumPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"

}

#---Set Alarm Action for High Priority Alarms---

Foreach ($HighPriorityAlarm in $HighPriorityAlarms) {

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail| Remove-AlarmAction -Confirm:$false

    Set-AlarmDefinition "$HighPriorityAlarm" -ActionRepeatMinutes (60 * 2) # 2 hours

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | New-AlarmAction -Email -To @($MailtoAddresses)

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Green" -EndStatus "Yellow"

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | Get-AlarmActionTrigger | Select -First 1 | Remove-AlarmActionTrigger -Confirm:$false

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Red" -Repeat

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Red" -EndStatus "Yellow"

    Get-AlarmDefinition -Name "$HighPriorityAlarm" | Get-AlarmAction -ActionType SendEmail | New-AlarmActionTrigger -StartStatus "Yellow" -EndStatus "Green"

}

#---Disconnect from vCenter Server----

Disconnect-VIServer -Server $vCenterServer -Force:$true -Confirm:$false