WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Listing all Events for vCenter Server

Listing all Events for vCenter Server

12.16.2019 by William Lam // 4 Comments

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.

More from my site

  • Is vCenter Server & ESXi hosts using VMware Certificate Authority (VMCA) or custom CA certificates?
  • VMware PowerCLI for Mac OS X, Linux & More? Yes, please!
  • How to easily disable vMotion & Cross vCenter vMotion for a particular Virtual Machine?
  • How to install ESXi 5.5 Patch03 on the new Mac Pro 6,1?
  • Want to issue a VAAI UNMAP operation using the vSphere Web Client?

Categories // Automation, PowerCLI, VMware Cloud on AWS, vSphere Tags // event, PowerCLI, vSphere

Comments

  1. *protectedvirt.ninja says

    12/16/2019 at 1:17 pm

    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? 🙁

    Reply
  2. *protectedapplicationha says

    02/06/2020 at 9:45 am

    This post is great, but I wish you had more information on it

    Reply
  3. *protectedPradeep says

    01/11/2021 at 2:51 am

    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

    Reply
  4. *protectedPradeep says

    01/11/2021 at 3:03 am

    I have fixed this now by using the following command before running the script
    Connect-VIServer "vserver name"

    Reply

Leave a Reply to applicationhaCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025

 

Loading Comments...