Single pane for multiple vCenter alarms

When you have multiple vCenters it can be a pain to go through each one checking for alarms. Hence the script below. You can specify the vCenters you want to connect to and it will display a nice sortable/filterable grid view of all of the triggered alarms.

# Usage
.\Get-TriggeredAlarms -vCenters vc001,vc002
param (
	[String[]]$vCenters
)
 
Function Get-TriggeredAlarms {
	param (
		$vCenter = $(throw "A vCenter must be specified."),
		[System.Management.Automation.PSCredential]$credential
	)
 
	if ($credential) {
		$vc = Connect-VIServer $vCenter -Credential $credential
	}
	else {
		$vc = Connect-VIServer $vCenter
	}
 
	if (!$vc) {
		Write-Host "Failure connecting to the vCenter $vCenter."
		exit
	}
	$rootFolder = Get-Folder -Server $vc "Datacenters"
 
	foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {
		$alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime
		$alarm.VC = $vCenter
		$alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name
		$entity = Get-View -Server $vc $ta.Entity
		$alarm.Entity = (Get-View -Server $vc $ta.Entity).Name
		$alarm.EntityType = (Get-View -Server $vc $ta.Entity).GetType().Name	
		$alarm.Status = $ta.OverallStatus
		$alarm.Time = $ta.Time
		$alarm.Acknowledged = $ta.Acknowledged
		$alarm.AckBy = $ta.AcknowledgedByUser
		$alarm.AckTime = $ta.AcknowledgedTime		
		$alarm
	}
	Disconnect-VIServer $vCenter -Confirm:$false
}
 
Write-Host ("Getting the alarms from {0} vCenters." -f $vCenters.Length)
 
$alarms = @()
foreach ($vCenter in $vCenters) {
	Write-Host "Getting alarms from $vCenter."
	$alarms += Get-TriggeredAlarms $vCenter
}
 
$alarms | Out-GridView -Title "Triggered Alarms"

Comments (5)

  1. Zimeon

    Thank you for this, helped to understand getting alarm information better.

  2. Guilherme Stela

    Very Nice script. I’ve created one based on yours and use it every day. Thanks for sharing! =)

  3. Danny

    A very well purposed script. Exactly what I was looking to write and also used daily. Thank you!

  4. Anonymous

    How to use this function. Please explain?

  5. _nd345

    thank you!

Leave a Comment

Your email address will not be published.