Home > vSphere API > How to Get Event Type with vSphere API?

How to Get Event Type with vSphere API?

August 19th, 2010 Leave a comment Go to comments

There is a recent question asking how to get the type of event from vSphere API in my previous blog. On one hand, you can clearly see the types of events on a vSphere Client, for instance “info”, “warning”, “error”, and “user.” On the other hand, you cannot find any information about the type from a given event itself using vSphere API.

Strictly speaking an event just indicates something has happened. That is it. You can categorize it differently depending on your goal. The Event type itself in vSphere API models an event as what it is, not about how you look at it. This is a right design philosophy, but turns out to be a little tricky for you to figure out the type of an event.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


How does vSphere Client do the trick?

The trick is with the EventManager, which has a property called description typed as EventDescription[]. The EventDescription data object includes category sub-property which holds information about the possible categories/types of all events, namely “info”, “warning”, “error”, and “user.” This is exactly you find from vSphere Client.

Another sub-property of EventDescription is called eventInfo typed as EventDescriptionEventDetail[]. Each EventDescriptionEventDetail object has a key, a category, and several format strings. So the mapping is here! The following is a screen shot showing the “HostAddFailedEvent” as “error.” The reason I used Eclipse is because MOB does not show eventInfo correctly. You can optionally use the VI Java Browser.

The solution is now clear. All you need to do is to retrieve the eventInfo sub-property and establish the mapping locally for lookup. In Java, you can load them into a HashMap object for fast look up.

Note that the mapping is just what VMware looks at these events. You can change the mapping for your applications when appropriate. That is why I said current design follows right philosopy.

One important performance tip is that you should NOT retrieve it twice in a session because eventInfo doesn’t change with a particular server. I wouldn’t recommend you to persist it locally either because it’s that expensive to get it.

Following is the Java code if you want to inspect the eventInfo property.

import java.net.URL;

import com.vmware.vim25.EventDescription;
import com.vmware.vim25.TaskInfoState;
import com.vmware.vim25.VirtualDevice;
import com.vmware.vim25.VirtualDisk;
import com.vmware.vim25.mo.EventManager;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.Task;
import com.vmware.vim25.mo.VirtualMachine;

* @author Steve Jin

public class FindEventType
public static void main(String[] args) throws Exception
ServiceInstance si = new ServiceInstance(new URL("<a href="https://server/sdk">https://server/sdk</a>"), "root", "password", true);
EventManager em = si.getEventManager();

EventDescription ed = em.getDescription();
// set a break point here to inspect the ed variable for more info


Categories: vSphere API Tags: , ,
  1. Vishal
    September 7th, 2010 at 01:48 | #1


    Why is there no DatacenterRemovedEvent? what do i get when datacenter is removed?


  2. Vishal
    September 7th, 2010 at 02:45 | #2


    If i capture an event lets say DatacenterCreated event, How do i know its severity in VIClient. I understand that EventDescription has the events defined, but i an trying to look at the event get the severity code and look up the EventDescriptionEventDetail array. event after reading this blog that was not clear.

  3. September 11th, 2010 at 00:30 | #3

    Good question. I will write a blog on this soon. Stay tuned.


  4. September 11th, 2010 at 00:33 | #4

    You can look up the EventDescriptionDetail array by matching the key with the event type. Once you find one item in the array, you can get its category: error, warning, info, and user.


  5. Vishal
    September 13th, 2010 at 12:10 | #5

    Here is the code that works, Not sure if there is better way of doing it though, This seems inefficient and prone for errors.

    Sample code—

    private void initialize() {
    _eventManager = si.getEventManager();
    _rootFolder = si.getRootFolder();
    eventDesc = _eventManager.getDescription();
    eventInfo = eventDesc.getEventInfo();

    private void processEvent(Event anEvent) {
    System.out.println(“\n———-” + “\n Severity: “+ getSeverity(anEvent.getClass().getName())+” Event ID: ” + anEvent.getKey() + ” Event: ”
    + anEvent.getClass().getName() + ” FullFormattedMessage: ” + anEvent.getFullFormattedMessage()
    + “\n———-\n”);

    private String getSeverity(String eventKey) {
    // strip com.vmware.vim25. from eventKey
    int beginIndex = 17; // skip 17 chars
    String eventName = eventKey.substring(beginIndex);
    for (EventDescriptionEventDetail info: eventInfo) {
    if (info.key.equals(eventName))
    return info.category;
    return “Unknown”;



    Event Details follows:

    Severity: info Event ID: 942261 Event: com.vmware.vim25.DatacenterRenamedEvent FullFormattedMessage: Renamed datacenter from XXX-Datacenter2 to XXX-Datacenter3

  6. Vishal
    September 14th, 2010 at 14:06 | #6


    Thanks for the blog, Any comment on my implementation, is there any way we can optimize it, it seems too round about way of getting the severity. The requirement i have from customers is to see the same severity for the events.

  7. September 14th, 2010 at 19:14 | #7

    Hi Vishal,

    As you pointed out, your implementation can be optimized. You want to load the event info array into a HashMap. It would speed up look up dramatically.


  8. Sharninder
    June 15th, 2015 at 05:05 | #8

    Hi Steve,

    Why isn’t there any event for moving a host into a cluster. I’m talking specifically about Moving the host by dragging and dropping it using the vsphere client. When I to this, the only event I seem to get is a TaskEvent, which is not useful to find out the source and target of the event for example. When I add a host to a cluster, I get hostAddedEvent which has much more info.

  9. Vivek
    May 12th, 2017 at 07:02 | #9

    Hi Steve,

    I am using vsphere API 6. I am not able to get reference of EventManager. In fact i do not see any class by the name of EventManager at all. Any suggestions?


  10. May 13th, 2017 at 19:13 | #10

    What APIs are you using, vijava or vijavaNG? Are you connecting to ESXi directly?

  11. Vivek
    May 15th, 2017 at 01:48 | #11

    @Steve Jin
    None of them. I am using the vim25 form vmware itself. I tried using vijava once but then my call to EventManager.QueryEvents returns with error as “Not implemented…”. So i assumed that is not supported on the server.

  12. Vivek
    May 15th, 2017 at 23:42 | #12

    @Steve Jin
    In fact, i also tried using vijava. When i use EventManager.QueryEvents to retrieve events i get an error as “–Not Implemented–” and the call fails to bring any events.

  1. September 14th, 2010 at 00:10 | #1