Skip to content

Instantly share code, notes, and snippets.

@crookedstorm
Created February 18, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crookedstorm/3b3110aae0ec306dcdde to your computer and use it in GitHub Desktop.
Save crookedstorm/3b3110aae0ec306dcdde to your computer and use it in GitHub Desktop.
A quick script to dump the currently-configured alarms of a number of vCenters.
Add-PSSnapin VMware.VimAutomation.Core
#A list of vCenter servers, one per line
$vcenterservers = Get-Content "vCenter_Servers.txt"
foreach ($vcenterserver in $vcenterservers)
{
Connect-VIServer -Server $vcenterserver -WarningAction SilentlyContinue | Out-Null
$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 }}}
}
$outfile = "alarms" + $vcenterserver + ".csv"
$output | Export-Csv $outfile -UseCulture -NoTypeInformation
Disconnect-VIServer -Server $vcenterserver -Force:$true -Confirm:$false
}
Remove-PSSnapin VMware.VimAutomation.Core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment