Exemple #1
0
    def __init__(self, server, entity=None, recursion=None, types=None, chain_id=None):
        """Creates a Event History Collector that gathers Event objects.
        based on the provides filters.
          * server: the connected VIServer instance
          * entity: Entity MOR, if provided filters events related to this entity
          * recursion: If 'entity' is provided then recursion is mandatory.
          specification of related managed entities in the inventory hierarchy
          should be either: 'all', 'children', or 'self'
          * types: if provided, limits the set of collected events by their
          types.
          * chain_id: if provided, retrieves events by chain ID
        """

        super(VIEventHistoryCollector, self).__init__(server)

        if entity and not VIMor.is_mor(entity):
            raise VIException("Entity should be a MOR object",
                              FaultTypes.PARAMETER_ERROR)

        if entity and not recursion in [Recursion.ALL, Recursion.CHILDREN,
                                        Recursion.SELF]:
            raise VIException("Recursion should be either: "
                              "'all', 'children', or 'self'",
                              FaultTypes.PARAMETER_ERROR)

        try:
            event_manager = server._do_service_content.EventManager
            request = VI.CreateCollectorForEventsRequestMsg()
            _this = request.new__this(event_manager)
            _this.set_attribute_type(event_manager.get_attribute_type())
            request.set_element__this(_this)

            _filter = request.new_filter()

            if types and not isinstance(types, list):
                types = [types]
            if types:
                _filter.set_element_eventTypeId(types)

            if chain_id is not None:
                _filter.set_element_eventChainId(chain_id)

            if entity:
                entity_filter = _filter.new_entity()
                mor_entity = entity_filter.new_entity(entity)
                mor_entity.set_attribute_type(entity.get_attribute_type())
                entity_filter.set_element_entity(mor_entity)
                entity_filter.set_element_recursion(recursion)
                _filter.set_element_entity(entity_filter)

            request.set_element_filter(_filter)
            resp = server._proxy.CreateCollectorForEvents(request)._returnval

        except (VI.ZSI.FaultException) as e:
            raise VIApiException(e)

        self._mor = resp
        self._props = VIProperty(self._server, self._mor)
    def __init__(self, server, include_types=None, include_users=None, beginTime=None, endTime=None):
        """Creates an Event History Collector that gathers Event objects based on the 
        provides filters.
          * server: the connected VIServer instance
          * include_types: if provided, limits the set of collected events by their 
            types. Should be a list of possible types (like 'UserLoginSessionEvent')
          * include_users [tuple([user1,userx]:list,system:boolean]: if provided, limits the set of 
            collected events to those events produced by any of the users indicated in the list.
            The format is a tuple with a list of possible users as the first parameter, and a 
            boolean value to indicate if system user is included or not as second parameter.
          * beginTime [time tuple]: The time from which available history 
            events are gathered. Corresponds to server time. When the beginTime
            is omitted, the returned events start from the first available
            event in the system.
          * endTime [time tuple]: The time up to which available history
            events are gathered. Corresponds to server time. When the endTime
            is omitted, the returned result includes up to the most recent
            event.
        """

        self._server = server
        self._mor = None
        
        try:
            event_manager = server._do_service_content.EventManager
            request = VI.CreateCollectorForEventsRequestMsg()
            _this = request.new__this(event_manager)
            _this.set_attribute_type(event_manager.get_attribute_type())
            request.set_element__this(_this)
                   
            _filter = request.new_filter()
            
            if(beginTime or endTime):
                do_EventFilterSpecByTime = _filter.new_time()
                
                if(beginTime):
                    do_EventFilterSpecByTime.set_element_beginTime(beginTime)

                if(endTime):
                    do_EventFilterSpecByTime.set_element_endTime(endTime)

                _filter.set_element_time(do_EventFilterSpecByTime)
            
            if(include_types):
                _filter.set_element_eventTypeId(include_types)

            if(include_users):
                do_EventFilterSpecByUser = _filter.new_userName()
                
                # Mandatory parameter
                do_EventFilterSpecByUser.set_element_systemUser(include_users[1])
                
                # Only add the list of users is there is at least one entry
                if(include_users[0]):
                    do_EventFilterSpecByUser.set_element_userList(include_users[0])

                _filter.set_element_userName(do_EventFilterSpecByUser)
                
            request.set_element_filter(_filter)
            resp = server._proxy.CreateCollectorForEvents(request)._returnval
        
        except (VI.ZSI.FaultException), e:
            raise VIApiException(e)