示例#1
0
    def getEdges(self):

        # We are saying below that from the container's perspective, we depend
        # on the physical node. We are agreeing with the ImpactEdge defined in
        # DeviceRelationsProvider, just expressing this identical relationship
        # from the Container's perspective. When defining ImpactEdges, you
        # always want to define impact relationships from both sides like this.

        yield ImpactEdge(
            IGlobalIdentifier(self._object.device()).getGUID(),
            IGlobalIdentifier(self._object).getGUID(),
            self.relationship_provider
        )

        # Try to find a device that exists because we are running net-snmp or have ssh monitoring
        # going direct to the container. If we find such a device, then this device *is* the container.
        # We, the container component, are dependent on this device. The device is dependent on us.
        # The code below yields both ImpactEdges from the container component's perspective.

        md = self._object.getManagedDevice()
        if md:
            e1 = IGlobalIdentifier(self._object.device()).getGUID()
            e2 = IGlobalIdentifier(md).getGUID()

            yield ImpactEdge(self.relationship_provider, e1, e2)
            yield ImpactEdge(self.relationship_provider, e2, e1)
 def get_guid(self, ob):
     """hackish way to do this"""
     gid = IGlobalIdentifier(ob)
     try:
         gid.create(force=True, update_global_catalog=False)
     except:
         pass
 def getEdges(self):
     cpu = self._object
     device = cpu.device()
     if isinstance(device, LinuxDevice):
         yield ImpactEdge(
             IGlobalIdentifier(device).getGUID(),
             IGlobalIdentifier(cpu).getGUID(), self.relationship_provider)
示例#4
0
    def getEdges(self):

        # We are saying below, that from the device's perspective, each container
        # depends upon us.

        devguid = IGlobalIdentifier(self._object).getGUID()
        for ve in self._object.openvz_containers():

            # For ImpactEdges, the second argument depends upon the first argument:

            yield ImpactEdge(
                devguid,
                IGlobalIdentifier(ve).getGUID(),
                self.relationship_provider
            )

        comp = self._object.getOpenVZComponentOnHost()
        if comp:

            # we are a device monitored thru SNMP or ssh that is an OpenVZ container. The
            # call above found the host we are running on, and the component representing
            # us underneath it. We are now going to say that we *are* the component, from
            # the container device's perspective. We depend on it, and it depends on us:

            e1 = IGlobalIdentifier(comp).getGUID()
            e2 = IGlobalIdentifier(self._object.device()).getGUID()

            yield ImpactEdge(e1, e2, self.relationship_provider)
            yield ImpactEdge(e2, e1, self.relationship_provider)
示例#5
0
    def createTrigger(self, name, uuid=None, rule=None):
        name = str(name)

        zodb_triggers = self._getTriggerManager().objectValues()
        zodb_trigger_names = set(t.id for t in zodb_triggers)
        if name in zodb_trigger_names:
            raise DuplicateTriggerName, (
                'The id "%s" is invalid - it is already in use.' % name)

        triggerObject = Trigger(name)
        self._getTriggerManager()._setObject(name, triggerObject)
        acquired_trigger = self._getTriggerManager().findChild(name)

        if uuid:
            IGlobalIdentifier(acquired_trigger).guid = str(uuid)
        else:
            IGlobalIdentifier(acquired_trigger).create()

        self.triggerPermissions.setupTrigger(acquired_trigger)

        trigger = zep.EventTrigger()
        trigger.uuid = IGlobalIdentifier(acquired_trigger).guid
        trigger.name = name
        trigger.rule.api_version = 1
        trigger.rule.type = zep.RULE_TYPE_JYTHON

        if rule and 'source' in rule:
            trigger.rule.source = rule['source']
        else:
            trigger.rule.source = ''

        self.triggers_service.addTrigger(trigger)

        log.debug('Created trigger with uuid: %s ' % trigger.uuid)
        return trigger.uuid
示例#6
0
    def importTriggers(self, triggers):
        """
        Add any new trigger definitions to the system.

        Note: modifies the triggers argument
              to add 'new_uuid' to the definition.

        Does not attempt to link a trigger to a notification.
        """
        existingTriggers = [x['name'] for x in self.getTriggerList()]
        existingUsers = {
            "{} (User)".format(x.id): IGlobalIdentifier(x).getGUID()
            for x in self._dmd.ZenUsers.getAllUserSettings()
        }
        existingUsers.update({
            "{} (Group)".format(x.id): IGlobalIdentifier(x).getGUID()
            for x in self._dmd.ZenUsers.getAllGroupSettings()
        })

        removeDataList = ['subscriptions']

        imported = 0
        for trigger in triggers:
            name = trigger.get('name')
            if name is None:
                log.warn("Missing name in trigger definition: %s", trigger)
                continue
            if name in existingTriggers:
                log.warn("Skipping existing trigger '%s'", name)
                continue

            data = deepcopy(trigger)
            trigger['new_uuid'] = data['uuid'] = self.addTrigger(name)

            # Cleanup
            for key in removeDataList:
                if key in data:
                    del data[key]

            # Don't delete data from list you're looping through
            data['users'] = []
            for user in trigger.get('users', []):
                if user['label'] in existingUsers:
                    newuser = deepcopy(user)
                    newuser['value'] = existingUsers[user['label']]
                    data['users'].append(newuser)
                else:
                    log.warning("Unable to find trigger %s user '%s' on this"
                                " server -- skipping", name, user)

            # Make changes to the definition
            self.updateTrigger(**data)
            imported += 1

        return imported
    def getEdges(self):
        for base_edge in BaseRelationshipDataProvider.getEdges(self):
            yield base_edge

        software_component = self.adapted.openstack_softwareComponent()
        if software_component:
            # impact the corresponding software software component
            yield ImpactEdge(
                IGlobalIdentifier(self.adapted).getGUID(),
                IGlobalIdentifier(software_component).getGUID(),
                self.relationship_provider)
示例#8
0
 def fetchRecipientOption(self, recipient):
     my_type = 'group' if isinstance(recipient, GroupSettings) else 'user'
     return dict(
         type=my_type,
         label='%s (%s)' % (recipient.getId(), my_type.capitalize()),
         value=IGlobalIdentifier(recipient).getGUID(),
     )
示例#9
0
    def __call__(self, eventContext):
        eventContext.log.debug('Mapping and Transforming event')
        evtclass = self._manager.lookupEventClass(eventContext)
        transform_enabled = evtclass.transformEnabled
        if transform_enabled:
            apply_transforms = getattr(eventContext.event, 'apply_transforms',
                                       True)
            if not apply_transforms:
                eventContext.log.debug(
                    'Not applying transforms, regexes or zProperties because apply_transforms'
                    ' was false')
        else:
            eventContext.log.debug(
                'Not applying transforms, transformEnabled is set to False.')
            apply_transforms = False
        if evtclass:
            self._tagEventClasses(eventContext, evtclass)

            if apply_transforms:
                evtclass.applyExtraction(eventContext.eventProxy)
                evtclass.applyValues(eventContext.eventProxy)
            if eventContext.eventProxy.eventClassMapping:
                eventContext.event.event_class_mapping_uuid = IGlobalIdentifier(
                    evtclass).getGUID()
            if apply_transforms:
                evtclass.applyTransform(eventContext.eventProxy,
                                        eventContext.deviceObject,
                                        eventContext.componentObject)
        return eventContext
示例#10
0
 def _getTags(self):
     guids = []
     us = self.context.dmd.ZenUsers.getUserSettings()
     if us.hasNoGlobalRoles():
         for ar in us.getAllAdminRoles():
             guids.append(IGlobalIdentifier(ar.managedObject()).getGUID())
     return guids
示例#11
0
 def fetchRecipientOption(self, recipient):
     my_type = 'group' if isinstance(recipient, GroupSettings) else 'user'
     return {
         'type': my_type,
         'label': '%s (%s)' % (recipient.getId(), my_type.capitalize()),
         'value': IGlobalIdentifier(recipient).getGUID(),
     }
示例#12
0
    def get_nodes_list(self, sort=False):
        """
        Returns list of devices and networks to index
        """
        if self.options.device:
            device = self.dmd.Devices.findDevice(self.options.device)
            if device:
                log.info(
                    "Updating connections for device %s",
                    self.options.device
                )
                return [device]
            else:
                log.error(
                    "Device with id %s was not found",
                    self.options.device
                )
                return []

        nodes = chain.from_iterable([
            self.dmd.Devices.getSubDevicesGen(),
            self.dmd.Networks.getSubNetworks()])
        if not sort:
            return list(nodes)
        return sorted(nodes, key=lambda x: IGlobalIdentifier(x).getGUID())
    def testDeviceProxyIntegrity(self):
        self.assertTrue(self._modeled)
        hosts = self.d.getDeviceComponents(type='OpenStackInfrastructureHost')
        self.assertEquals(len(hosts), 5)
        bugs = getHostObjectByName(hosts, 'bugs')
        wily = getHostObjectByName(hosts, 'wily')
        liberty = getHostObjectByName(hosts, 'liberty')
        leghorn = getHostObjectByName(hosts, 'leghorn')

        # Ensure the following hosts don't have proxy_device():
        self.assertIsNone(wily.proxy_device())
        self.assertIsNone(bugs.proxy_device())
        self.assertIsNotNone(liberty.proxy_device())

        # Ensure the leghorn has foghorn as proxy_device():
        leghorn_proxy = leghorn.proxy_device()
        self.assertEquals(leghorn_proxy.id, 'foghorn.zenoss.local')
        self.assertEquals(leghorn_proxy.manageIp, '192.168.56.112')

        # Break the proxy device linkage by changing leghorn device's uuid
        old_uuid = leghorn.openstackProxyDeviceUUID
        IGlobalIdentifier(leghorn_proxy).setGUID(
            '97e184b1-ed49-481e-bb7c-cce3bba1d171')

        # Test fixage of the proxy_device claim for leghorn:
        with FilteredLog(
            ["zen.OpenStackDeviceProxyComponent"],
            ["but it is not linked back.  Disregarding linkage."]):
            self.assertEquals(leghorn.proxy_device(), leghorn_proxy)

        self.assertNotEquals(leghorn.openstackProxyDeviceUUID, old_uuid)
示例#14
0
    def _getTriggerGuid(self, trigger):
        """
        @param trigger: The trigger object in zodb.
        @type trigger: Products.ZenModel.Trigger.Trigger

        This method was created to provide a hook for unit tests.
        """
        return IGlobalIdentifier(trigger).guid
示例#15
0
 def need_maintenance(self):
     guid = IGlobalIdentifier(self).getGUID()
     device = GUIDManager(self.dmd).getObject(
         getattr(self, 'openstackProxyDeviceUUID', None))
     if device and getattr(device, 'openstackProxyComponentUUID', None) \
             and device.openstackProxyComponentUUID == guid:
         return False
     return True
    def get_remote_guids(self, methodname):
        """Generate object GUIDs returned by adapted.methodname()."""

        method = getattr(self.adapted, methodname, None)
        if not method or not callable(method):
            return

        r = method()
        if not r:
            return

        try:
            for obj in r:
                yield IGlobalIdentifier(obj).getGUID()

        except TypeError:
            yield IGlobalIdentifier(r).getGUID()
示例#17
0
 def uuidFromBrain(self, brain):
     """
     Helper method to deal with catalog brains which are out of date. If
     the uuid is not set on the brain, we attempt to load it from the
     object.
     """
     uuid = brain.uuid
     return uuid if uuid else IGlobalIdentifier(brain.getObject()).getGUID()
示例#18
0
 def _getUserUuid(self, userName):
     # We have to call _getOb instead of getUserSettings here because the
     # latter will create a new user settings object even if the user is
     # not known.
     try:
         user = self._dmd.ZenUsers._getOb(userName)
         return IGlobalIdentifier(user).getGUID()
     except AttributeError:
         raise Exception('Could not find user "%s"' % userName)
示例#19
0
    def get_remote_guids(self, methodname):
        """Generate object GUIDs returned by adapted.methodname()."""
        method = getattr(self.adapted, methodname, None)
        if not method or not callable(method):
            DEFAULTLOG.warning("no %r relationship or method for %r",
                               methodname, self.adapted.meta_type)

            return

        r = method()
        if not r:
            return

        try:
            for obj in r:
                yield IGlobalIdentifier(obj).getGUID()

        except TypeError:
            yield IGlobalIdentifier(r).getGUID()
示例#20
0
    def _setTriggerGuid(self, trigger, guid):
        """
        @param trigger: The trigger object to set the guid on.
        @type trigger: Products.ZenModel.Trigger.Trigger
        @param guid: The guid
        @type guid: str

        This method was created to provide a hook for unit tests.
        """
        IGlobalIdentifier(trigger).guid = guid
示例#21
0
def _user_uuid(dmd, userName):
    # We have to call _getOb instead of getUserSettings here because the
    # latter will create a new user settings object even if the user is
    # not known.
    try:
        user = dmd.ZenUsers._getOb(userName)
        return IGlobalIdentifier(user).getGUID()
    except Exception:
        if log.isEnabledFor(logging.DEBUG):
            log.exception("Failed to look up user UUID for %s", userName)
示例#22
0
    def testActorReidentificationFromEventClassKeyTransform(self):
        """
        Verify that changing the device in a transform properly reidentifies the device
        when matching an event by eventClassKey.
        """

        device_a = self.dmd.Devices.createInstance("transform_device_a")

        # Related: ZEN-1419
        # If you change a device from within a transform like so:
        #
        #   evt.device = 'my_new_device'
        #
        # The processing pipeline will recognize this and re-run the
        # identification pipes. Before it re-runs these pipes though, it will
        # clear several properties related to the device, one of which is the
        # device/element UUID. During the Identification pipe, if the UUID
        # is missing, it will try one last time to lookup the element
        # using the identifier and the ip address. If we do not set an
        # ip address here, this test will not be completely testing the
        # reidentification logic.
        device_a.setManageIp("192.168.100.100")

        device_b = self.dmd.Devices.createInstance("transform_device_b")

        _transform_key = 'transform_test_key'
        _transform = """
evt.device = '%s'
        """
        self.dmd.Events.createOrganizer('/transform_test')
        self.dmd.Events.transform_test.transform = _transform % device_b.id

        # the organizer above contains the transform, no create an instance
        # that actually contains the event class key.
        self.dmd.Events.transform_test.createInstance(_transform_key)

        event = Event()
        event.actor.element_identifier = device_a.id
        event.actor.element_type_id = DEVICE
        event.severity = SEVERITY_WARNING
        event.summary = 'Testing transforms.'

        detail = event.details.add()
        detail.name = EventProxy.DEVICE_IP_ADDRESS_DETAIL_KEY
        detail.value.append(device_a.getManageIp())

        # Match the transform by event_class_key
        event.event_class_key = _transform_key
        processed = self._processEvent(event)

        self.assertEquals(device_b.id,
                          processed.event.actor.element_identifier)
        self.assertEquals(
            IGlobalIdentifier(device_b).getGUID(),
            processed.event.actor.element_uuid)
示例#23
0
 def getManagedObjectGuids(self):
     """
     If the currently logged in user is a restricted user this will return
     all of the guids for items he can administer.
     """
     guids = []
     us = self.context.dmd.ZenUsers.getUserSettings()
     if us.hasNoGlobalRoles():
         for ar in us.getAllAdminRoles():
             guids.append(IGlobalIdentifier(ar.managedObject()).getGUID())
     return guids
示例#24
0
        def _setProdState(devices_batch):
            for device in devices_batch:
                guid = IGlobalIdentifier(device).getGUID()
                # In case we try to move Component Group into MW
                # some of objects in CG may not have production state
                # we skip them.
                if ending:
                    # Note: If no maintenance windows apply to a device, then the
                    #       device won't exist in minDevProdStates
                    # This takes care of the case where there are still active
                    # maintenance windows.
                    minProdState = minDevProdStates.get(
                        guid, device.getPreMWProductionState())

                elif guid in minDevProdStates:
                    minProdState = minDevProdStates[guid]

                else:  # This is impossible for us to ever get here as minDevProdStates
                    # has been added by self.fetchDeviceMinProdStates()
                    log.error(
                        "The device %s does not appear in any maintenance"
                        " windows (including %s -- which is just starting).",
                        device.id, self.displayName())
                    continue

                # ZEN-13197: skip decommissioned devices
                if device.getPreMWProductionState(
                ) and device.getPreMWProductionState() < 300:
                    continue

                self._p_changed = 1
                # Changes the current state for a device, but *not*
                # the preMWProductionState
                oldProductionState = self.dmd.convertProdState(
                    device.getProductionState())
                # When MW ends Components will acquire production state from device
                if not minProdState:
                    newProductionState = "Acquired from parent"
                else:
                    newProductionState = self.dmd.convertProdState(
                        minProdState)
                log.info("MW %s changes %s's production state from %s to %s",
                         self.displayName(), device.id, oldProductionState,
                         newProductionState)
                audit('System.Device.Edit',
                      device,
                      starting=str(not ending),
                      maintenanceWindow=self.displayName(),
                      productionState=newProductionState,
                      oldData_={'productionState': oldProductionState})
                if minProdState is None:
                    device.resetProductionState()
                else:
                    device.setProdState(minProdState, maintWindowChange=True)
示例#25
0
    def getEventSummaries(self,
                          offset,
                          limit=1000,
                          sort=None,
                          filter=None,
                          exclusion_filter=None,
                          client_fn=None,
                          use_permissions=False):
        if client_fn is None:
            client_fn = self.client.getEventSummaries
        if filter is not None and isinstance(filter, dict):
            filter = from_dict(EventFilter, filter)
        if exclusion_filter is not None and isinstance(exclusion_filter, dict):
            exclusion_filter = from_dict(EventFilter, exclusion_filter)
        if sort is not None:
            sort = tuple(self._getEventSort(s) for s in safeTuple(sort))

        result = None

        if use_permissions:
            user = getSecurityManager().getUser()
            userSettings = self._dmd.ZenUsers._getOb(user.getId())
            hasGlobalRoles = not userSettings.hasNoGlobalRoles()
            if not hasGlobalRoles:
                adminRoles = userSettings.getAllAdminRoles()
                if adminRoles:
                    # get ids for the objects they have permission to access
                    # and add to filter
                    ids = [
                        IGlobalIdentifier(x.managedObject()).getGUID()
                        for x in adminRoles
                    ]
                    if filter is None:
                        filter = EventFilter()
                    tf = filter.tag_filter.add()
                    tf.tag_uuids.extend(ids)
                else:
                    # no permission to see events, return 0
                    result = {
                        'total': 0,
                        'events': [],
                    }

        if not result:
            result = self._getEventSummaries(source=partial(
                client_fn,
                filter=filter,
                exclusion_filter=exclusion_filter,
                sort=sort),
                                             offset=offset,
                                             limit=limit)
        return result
示例#26
0
    def notificationSubscribesToSignal(self, notification, signal):
        """
        Determine if the notification matches the specified signal.

        @param notification: The notification to check
        @type notification: NotificationSubscription
        @param signal: The signal to match.
        @type signal: zenoss.protocols.protbufs.zep_pb2.Signal

        @rtype boolean
        """
        return signal.subscriber_uuid == IGlobalIdentifier(
            notification).getGUID()
示例#27
0
    def ensure_valid_claim(self, device):
        component_guid = IGlobalIdentifier(self).getGUID()
        device_guid = IGlobalIdentifier(device).getGUID()
        valid = True

        # Confirm forward linkage
        if getattr(self, 'openstackProxyDeviceUUID', None) != device_guid:
            valid = False

        # Confirm reverse linkage
        if getattr(device, 'openstackProxyComponentUUID',
                   None) != component_guid:
            valid = False

        if not valid:
            # the linkage is broken in at least one direction.  Just re-claim
            # it to set it right.
            LOG.info(
                "%s component '%s' linkage to device '%s' is broken. "
                "Re-claiming it.", self.meta_type, self.name(), device.name())
            self.claim_proxy_device(device)
        return device
示例#28
0
 def getMaxSeverity(self, me):
     from Products.Zuul.facades import getFacade
     """ Returns the severity of the most severe event. """
     zep = getFacade('zep')
     try:
         # Event class rainbows show all events through DEBUG severity
         uuid = IGlobalIdentifier(me).getGUID()
         return zep.getWorstSeverityByUuid(uuid)
     except TypeError:
         log.warn(
             "Attempted to query events for %r which does not have a uuid" %
             self)
         return 0
示例#29
0
 def uuid(self):
     """
     Object's uuid. This is a metadata column.
     """
     try:
         # We don't need create() to update the global catalog, because by definition
         # this is only called when the object is going to be indexed.
         return IGlobalIdentifier(
             self._context).create(update_global_catalog=False)
     except ConflictError:
         raise
     except Exception:
         pass
示例#30
0
    def _add_node(self, node, keys):
        """
        Adds node GUID to list of all indexed nodes
        and list of associated connections' keys
        """
        guid = IGlobalIdentifier(node).getGUID()
        cat = self.catalog
        keys_key = cat.prepId(cat.b_prefix + guid)

        pipe = cat.redis.pipeline(transaction=False)
        pipe.sadd(cat.prepId(cat.existing_nodes_key), guid)
        for key in set(keys):
            pipe.sadd(keys_key, key)
        pipe.execute()
示例#31
0
    def cutover(self, dmd):
        force = getattr(dmd, "guid_table", None) is None

        log.debug("Creating GUIDs...")
        identifiables = [o.__name__ for o in IGloballyIdentifiable.dependents.keys()]
        catalog = dmd.global_catalog
        update_metadata = False
        try:
            catalog._catalog.addColumn("uuid")
            update_metadata = True
        except CatalogError:
            # Column exists
            pass
        for brain in ICatalogTool(dmd).search(identifiables):
            try:
                obj = brain.getObject()
            except Exception:
                continue
            identifier = IGlobalIdentifier(obj)
            if force or not identifier.getGUID():
                guid = identifier.create(force)
                log.debug("Created guid for %s: %s", "/".join(obj.getPrimaryPath()[3:]), guid)
            if update_metadata:
                catalog.catalog_object(obj, idxs=(), update_metadata=True)