Java 类com.vmware.vim25.mo.EventManager 实例源码

项目:vijava    文件:QueryEvent.java   
public static void main(String[] args) throws Exception 
{

    if (args.length != 3) 
    {
        usage();
        return;
    }

    String urlStr = args[0];
    String username = args[1];
    String password = args[2];

    System.out.println("Connecting to " + urlStr + " as " + username);

    ServiceInstance si = new ServiceInstance(new URL(urlStr), username,
            password, true);

    System.out.println("info---" + si.getAboutInfo().getFullName());

    // Displays all the Events with Full Formatted message
    try 
    {
        EventManager _eventManager = si.getEventManager();
        EventFilterSpec eventFilter = new EventFilterSpec();

        EventHistoryCollector history = _eventManager
                .createCollectorForEvents(eventFilter);
        Event[] events = history.getLatestPage();

        System.out.println("Events In the latestPage are : ");
        for (int i = 0; i < events.length; i++) 
        {
            Event anEvent = events[i];
            System.out.println("Event: " + anEvent.getClass().getName()
                    + "  FullFormattedMessage: "
                    + anEvent.getFullFormattedMessage());
        }
    } catch (Exception e)
    {
        System.out.println("Caught Exception : " + " Name : "
                + e.getClass().getName() + " Message : " + e.getMessage()
                + " Trace : ");
        e.printStackTrace();
    }

    si.getServerConnection().logout();

}
项目:vijava    文件:QueryEvents.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java QueryEvents " 
        + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
      new URL(args[0]), args[1], args[2], true);

  // get the latest event and print it out
  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"});

  Event[] events = evtMgr.queryEvents(efs);

  // print each of the events
  for(int i=0; events!=null && i<events.length; i++) 
  {
    System.out.println("\nEvent #" + i);
    printEvent(events[i]);
  }

  si.getServerConnection().logout();
}
项目:vijava    文件:QueryHistoricalEvents.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 3)
  {
    System.out.println("Usage: java QueryHistoricalEvents " 
      + "<url> <username> <password>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  EventManager evtMgr = si.getEventManager();

  if(evtMgr!=null)
  {
    EventFilterSpec eventFilter = new EventFilterSpec();
    EventHistoryCollector ehc = 
      evtMgr.createCollectorForEvents(eventFilter);

    int total = 0;

    Event[] latestEvts = ehc.getLatestPage();
    printEvents(latestEvts, 0);
    total += latestEvts==null? 0 : latestEvts.length;

    System.out.println("\nBefore Latest Page:");
    ehc.resetCollector();
    while(true)
    {
      Event[] events = ehc.readPreviousEvents(50);
      if(events==null)
      {
        break;
      }
      printEvents(events, total);
      total += events.length;
    }
  }
  si.getServerConnection().logout();
}