Another interesting question in the PowerCLI Community today.
David wanted to know if it was possible to track which VMs had been failed over to another ESXi host by HA.
With the Get-VIEventPlus function from my Get the vMotion/svMotion history post it is easy to get that informatiom from the Tasks and Events that are kept in the vCenter database.
But which event to look for ?
The Making Of
In the PowerCLI Community there are often questions on how track a specific type of event. The best source of information to start with is of course the VMware vSphere API Reference Documentation. Under the Data Object Types you’ll find most of the events that can occur in a vSphere environment.
But there are ways to make the search easier. In my Events – Part 7 : Working with extended events – Update Manager post I already provided a short script to produce a cross-reference of the available events in your vSphere environment.
This is an improved version of that script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$report = @() $eventMgr = Get-View EventManager $events = foreach($event in $eventMgr.Description.EventInfo){ New-Object PSOBject -Property @{ Key = $event.Key Category = $event.Category EventTypeId = &{ If('ExtendedEvent','EventEx' -contains $event.Key){ $event.FullFormat.Split('|')[0] } else{ $null}} Description = $event.Description } } $events | Export-Csv C:\events.csv -NoTypeInformation -UseCulture |
The resulting table looks something like this.
Important to remember here, there are 3 major categories of events: a regular Event, an EventEx and an ExtendedEvent. The hierarchy of these different object types looks like this.
Now that we have our events XRef, it’s a matter of doing a bit of searching. The Excel filtering options do wonders here. In this case it was obvious that the HA component produces a number of events that all seem to start with com.vmware.vc.HA. The one we were after had VmRestartedByHAEvent in the identifier. And the Description confirms that this was the event we were looking for.
We pass this EventTypeId with the EventType parameter to the Get-VIEventPlus function. This is explained in the description of the eventTypeId property on the EventFilterSpec object.
The script to get the specific events and produce a report is quite simple.
1 2 3 4 5 6 7 |
$entity = Get-Folder Datacenters $start = (Get-Date).AddMonths(-3) $Recurse = $false $eventTypes = "com.vmware.vc.ha.VmRestartedByHAEvent" Get-VIEventPlus -Entity $entity -Start $start -EventType $eventTypes | Select CreatedTime,@{N="VM";E={$_.Vm.Name}},@{N="ESX";E={$_.Host.Name}} |
The result looks something like this.
Enjoy !
Oskar Norén
Hi Luc,
Is it possible to retrieve the source host also?
I’ve been looking through the tasks and events in vSphere Client and via PowerCLI, but I can’t really find anything to bind the events together.
– Oskar
Ashish
Hi Luc,
Is it possible to retrieve the source host also?
I’ve been looking through the tasks and events in vSphere Client and via PowerCLI, but I can’t really find anything to bind the events together.
– Ashish
power_in_cli
hi,
how can I see the list of task snapshot failure on VM ?
As seen in the ESX Task view panel (not Event view).
I do not want to have the list of event but list task thougt PowerCLI.
thank you
Andreas Peetz
Hi Luc,
a while ago I published a handy little script that also automates this task and lists successful and also failed(!) HA restarts: See https://www.v-front.de/2012/06/how-to-list-vsphere-50-ha-restarts-with.html
– Andreas
LucD
Hi Andreas, nice script, and very useful.
I used the VMTN question to explain a bit how one can find out which events to look for. And to push my Get-VIEventPlus function of course 😉