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
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)
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.
virt.ninja says
Thanks Will, really handy. I'm guessing this'll show that tag attach/detach events still haven't made their way to the on prem appliance though, 7 months on? 🙁
applicationha says
This post is great, but I wish you had more information on it
Pradeep says
Hi
I am running this script from a different server then the vCenter server.
The script fails with the following error. Are you able to help please?
Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command
again.
At D:\PowerCLI\get-events-field.ps1:3 char:22
+ ... = Get-View $global:DefaultVIServer.ExtensionData.Content.EventManage ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Number of Events: 0
Out-File : Access to the path 'D:\PowerCLI\vcenter--events.csv' is denied.
At D:\PowerCLI\get-events-field.ps1:26 char:60
+ ... ConvertTo-Csv | Out-File -FilePath vcenter-$vcenterVersion-events.csv
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Pradeep says
I have fixed this now by using the following command before running the script
Connect-VIServer "vserver name"