I had a conversation with one of our VMware Cloud on AWS field leaders a couple of weeks ago at reInvent on his initial experience with the vCenter Event Broker Appliance (VEBA) Fling. There were lots great feedback but one thing that stood out to me which looks to have been a barrier to getting started was being able to figure out a specific vCenter Event and its respective identifier. Although the list of "default" vCenter Events are documented in the vSphere API, it is definitely not the first place most folks would go to look nor is it very intuitive to browse.

To be honest, this is not a unique ask for VEBA. I have also seen this requests come up from customers who are automating vCenter Alarms, which can also be based off of vCenter Events and the same question has come up on before. One challenge with such a request is that the number and the types of vCenter Events will vary from customer to customer depending on the number of 2nd and 3rd party solutions deployed, not to mention it will also vary from version to version. In addition, as a customer, you can also publish your own custom Events into vCenter Server which makes this difficult to provide a single list that would cover all possible scenarios.

Ultimately, this ask is completely valid and I started to look at the vSphere API to see if there was something that could help. It did not take look before I stumbled onto the EventDescription which is part of the EventManager, which provides a nice registry for all currently registered vCenter Events. Time for some Automation 🙂

Listing vCenter Server Events

Using the following PowerCLI snippet, you can generate a nice CSV report for all the vCenter Events that is available for your specific vCenter Server. The output contains the Event ID, Event Type (Standard, EventEx or ExtendedEvent) and Event Description.

$vcenterVersion = ($global:DefaultVIServer.ExtensionData.Content.About.ApiVersion) $eventMgr = Get-View $global:DefaultVIServer.ExtensionData.Content.EventManager $results = @() foreach ($event in $eventMgr.Description.EventInfo) { if($event.key -eq "EventEx" -or $event.key -eq "ExtendedEvent") { $eventId = ($event.FullFormat.toString()) -replace "\|.*","" $eventType = $event.key } else { $eventId = $event.key $eventType = "Standard" } $eventDescription = $event.Description $tmp = [PSCustomObject] @{ EventId = $eventId; EventType = $eventType; EventDescription = $($eventDescription.Replace("<","").Replace(">","")); } $results += $tmp } Write-Host "Number of Events: $($results.count)" $results | Sort-Object -Property EventId | ConvertTo-Csv | Out-File -FilePath vcenter-$vcenterVersion-events.csv 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 $vcenterVersion = ( $global : DefaultVIServer . ExtensionData . Content . About . ApiVersion ) $eventMgr = Get-View $global : DefaultVIServer . ExtensionData . Content . EventManager $results = @ ( ) foreach ( $event in $eventMgr . Description . EventInfo ) { if ( $event . key -eq "EventEx" -or $event . key -eq "ExtendedEvent" ) { $eventId = ( $event . FullFormat . toString ( ) ) -replace "\|.*" , "" $eventType = $event . key } else { $eventId = $event . key $eventType = "Standard" } $eventDescription = $event . Description $tmp = [ PSCustomObject ] @ { EventId = $eventId ; EventType = $eventType ; EventDescription = $ ( $eventDescription . Replace ( "<" , "" ) . Replace ( ">" , "" ) ) ; } $results += $tmp } Write-Host "Number of Events: $($results.count)" $results | Sort-Object -Property EventId | ConvertTo-Csv | Out-File -FilePath vcenter - $vcenterVersion -events . csv

To give you an idea of what the output could look like, I ran this script against a vanilla vSphere 6.7 Update 3 as well as the latest VMware Cloud on AWS 1.8 release and you can find the list of events in the following Github repo https://github.com/lamw/vcenter-event-mapping. As mentioned, every deployment can and will be slightly different and it is recommended that you run this script against your own vCenter Server to get an accurate list of vCenter Events that are applicable in your own environment.

Publishing Custom vCenter Events

In addition to listing all vCenter Events, you can also publish your own custom events into vCenter Server and this is actually how 2nd and 3rd party solutions can natively integrate their offerings and provide additional context directly into vCenter Server. Using the postEvent method, you can either "fake" an existing for vCenter Event for testing vCenter Alarms or you can create your own by leveraging the EventEx type.

Here is a very basic PowerCLI snippet on creating your own custom vCenter Event:

$eventMgr = Get-View $global:DefaultVIServer.ExtensionData.Content.EventManager $customEvent = New-Object VMware.Vim.EventEx $customEvent.eventTypeId = "vGhettoWelcomeEvent" $customEvent.message = "Hello from virtuallyGhetto" $customEvent.ChainId = "0" $customEvent.Key = "0" $customEvent.CreatedTime = $(Get-Date -Format g) $customEvent.UserName = "vGhetto-Bot" $eventMgr.postEvent($customEvent,$null) 1 2 3 4 5 6 7 8 9 10 11 $eventMgr = Get-View $global : DefaultVIServer . ExtensionData . Content . EventManager $customEvent = New-Object VMware . Vim . EventEx $customEvent . eventTypeId = "vGhettoWelcomeEvent" $customEvent . message = "Hello from virtuallyGhetto" $customEvent . ChainId = "0" $customEvent . Key = "0" $customEvent . CreatedTime = $ ( Get-Date -Format g ) $customEvent . UserName = "vGhetto-Bot" $eventMgr . postEvent ( $customEvent , $null )

Just like any other vCenter Event, this will show up in the vSphere UI as well as API.



One thing you may have noticed is the the description field does not actually contain the message we had configured and the reason for this is that the description field is actually managed by a different system. You actually need register a custom extension which provides a framework for detailing each custom event and its payload which can then be populated at runtime by additional arguments. This is outside of the scope of this blog post, but you can certainly explore this further by taking a look at the ExtensionManager in vCenter Server and some of the default extensions to get an idea of how this API works.