Created
February 18, 2015 16:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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