How to Get Event Type with vSphere API?

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

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.

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.

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.

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.

@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.

NEED HELP?

My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.