EventManager evtMgr = si.getEventManager();
Event latestEvent = evtMgr.getLatestEvent();
printEvent(latestEvent);
// create a filter spec for querying events
EventFilterSpec efs = new EventFilterSpec();
// limit to only error and warning
efs.setType(new String[] {"VmFailedToPowerOnEvent",
"HostConnectionLostEvent"});
// limit to error and warning only
efs.setCategory(new String[] {"error", "warning"});
// limit to the children of root folder
EventFilterSpecByEntity eFilter =
new EventFilterSpecByEntity();
eFilter.setEntity(si.getRootFolder().getMOR());
eFilter.setRecursion(
EventFilterSpecRecursionOption.children);
// limit to the events happened since a month ago
EventFilterSpecByTime tFilter = new EventFilterSpecByTime();
Calendar startTime = si.currentTime();
startTime.roll(Calendar.MONTH, false);
tFilter.setBeginTime(startTime);
efs.setTime(tFilter);
// limit to the user of "administrator"
EventFilterSpecByUsername uFilter =
new EventFilterSpecByUsername();
uFilter.setSystemUser(false);
uFilter.setUserList(new String[] {"administrator"});