Java 类com.vmware.vim25.EventFilterSpec 实例源码

项目:vijava    文件:VMEventsMonitor.java   
private void createEventHistoryCollector() throws Exception
{
    // Create an Entity Event Filter Spec to
    // specify the MoRef of the VM to be get events filtered for
    EventFilterSpecByEntity entitySpec = new EventFilterSpecByEntity();
    entitySpec.setEntity(_rootFolder.getMOR());
    entitySpec.setRecursion(EventFilterSpecRecursionOption.children);

    // set the entity spec in the EventFilter
    EventFilterSpec eventFilter = new EventFilterSpec();
    eventFilter.setEntity(entitySpec);

    // we are only interested in getting events for the VM.
    // Add as many events you want to track relating to vm.
    // Refer to API Data Object vmEvent and see the extends class list for
    // elaborate list of vmEvents
    eventFilter.setType(new String[] { "VmPoweredOffEvent",
            "VmPoweredOnEvent", "VmSuspendedEvent", "VmRenamedEvent" });

    // create the EventHistoryCollector to monitor events for a VM
    // and get the ManagedObjectReference of the EventHistoryCollector
    // returned
    _eventHistoryCollector = _eventManager
            .createCollectorForEvents(eventFilter);
}
项目:contrail-vcenter-plugin    文件:VCenterNotify.java   
private EventHistoryCollector createEventHistoryCollector(ManagedObject mo,
        String[] events) throws InvalidState, RuntimeFault, RemoteException
{
    if (eventManager == null) {
        s_logger.error("Cannot create EventHistoryCollector, eventManager is null");
        return null;
    }
    EventFilterSpec eventFilterSpec = new EventFilterSpec();
    eventFilterSpec.setType(events);

    // Create an Entity Event Filter Spec to
    // specify the MoRef of the MO to be get events filtered for
    EventFilterSpecByEntity entitySpec = new EventFilterSpecByEntity();
    entitySpec.setEntity(mo.getMOR());
    entitySpec.setRecursion(EventFilterSpecRecursionOption.children);
    // set the entity spec in the EventFilter
    eventFilterSpec.setEntity(entitySpec);

    if (vcenterConnectedTime != null) {
        EventFilterSpecByTime timeSpec = new EventFilterSpecByTime();
        timeSpec.setBeginTime(vcenterConnectedTime);
        // set the time spec in the EventFilter
        eventFilterSpec.setTime(timeSpec);
    }

    // create the EventHistoryCollector to monitor events for a VM
    // and get the ManagedObjectReference of the EventHistoryCollector
    // returned

    EventHistoryCollector collector = eventManager.createCollectorForEvents(eventFilterSpec);
    collector.setCollectorPageSize(1000);
    collectors.add(collector);

    return collector;
}
项目:vijava    文件:EventHistoryCollectorMonitor.java   
public static void main(String[] args) throws Exception
{
  CommandLineParser clp = new CommandLineParser(
      new OptionSpec[]{}, args);
  String urlStr = clp.get_option("url");
  String username = clp.get_option("username");
  String password = clp.get_option("password");

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

  EventManager evtMgr = si.getEventManager();

  if(evtMgr!=null)
  {
    EventFilterSpec eventFilter = new EventFilterSpec();
    EventHistoryCollector ehc = 
      evtMgr.createCollectorForEvents(eventFilter);
    Event[] events = ehc.getLatestPage();

    for (int i = 0; i < events.length; i++)
    {
      Event anEvent = events[i];
      System.out.println("Event: " + 
          anEvent.getClass().getName());
    }
  }
  si.getServerConnection().logout();
}
项目: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();
}
项目:jcloud-vsphere    文件:EventManagerApi.java   
EventHistoryCollector createCollectorForEvents(EventFilterSpec filter) throws InvalidState, RuntimeFault, RemoteException;
项目:jcloud-vsphere    文件:EventManagerApi.java   
List<Event> queryEvents(EventFilterSpec filter) throws RuntimeFault, RemoteException;