Пример #1
0
    def _buildMetric(self, context, dp, cf, extraRpn="", format=""):
        datasource = dp.datasource()
        dsId = datasource.id
        info = IInfo(dp)

        # find out our aggregation function
        agg = AGGREGATION_MAPPING.get(cf.lower(), cf.lower())
        rateOptions = info.getRateOptions()
        tags = self._buildTagsFromContextAndMetric(context, dsId)
        metricname = dp.name()
        key = self._get_key_from_tags(tags)
        search = _devname_pattern.match(key)
        if search:
            metricname = metrics.ensure_prefix(context.getMetricMetadata(),
                                               metricname)
        name = context.getResourceKey() + "|" + dp.name()
        metric = dict(metric=metricname,
                      aggregator=agg,
                      tags=tags,
                      rate=info.rate,
                      name=name)
        combined_metric = [metric]
        if rateOptions:
            metric['rateOptions'] = rateOptions
        if extraRpn:
            metric['emit'] = 'false'
            metric['name'] = "{}-raw".format(dp.name())
            new_metric = dict(expression="rpn:{}-raw,{}".format(
                dp.name(), extraRpn),
                              format=format,
                              name=name)
            combined_metric.append(new_metric)
        else:
            metric['format'] = format
        return combined_metric
Пример #2
0
    def editMaintWindow(self, params):
        """
        Edits the values of a maintenance window.  

        @type  params: dict
        @param params: 
        """
        obj = self._getObject(params['uid'])
        maintenanceWindows = []
        oldData = {}
        for s in obj.maintenanceWindows():
            maintenanceWindowInfo = IInfo(s)
            if (maintenanceWindowInfo.id == params['id']):
                durationString = s.niceDuration()
                durationDict = s.durationStringParser(durationString)
                oldData.update({
                    'repeat': s.repeat,
                    'durationMinutes': durationDict.get('minutes', '00'),
                    'uid': maintenanceWindowInfo.uid,
                    'durationHours': durationDict.get('hours', '00'),
                    'startProductionState': s.startProductionState,
                    'enabled': s.enabled,
                    'durationDays': durationDict.get('days', '0'),
                    'startDateTime': s.start,
                    'id': s.id
                })
                maintenanceWindowInfo.updateWindow(params)
            maintenanceWindows.append(maintenanceWindowInfo)

        audit('UI.MaintenanceWindow.Edit', params['uid'] + '/' + params['id'], oldData_=oldData, data_=params)
        return maintenanceWindows
    def getAvailableDashboards(self):
        """
        Available dashboards come from three places. Managers can access all dashboards.

        1. Global (they are on dmd.ZenUsers)
        2. The User Groups current user belongs to
        3. Any exclusive to that user
        """
        dashboards = []
        user = self._dmd.ZenUsers.getUserSettings()

        # 1. Global Dashboards
        dashboards.extend([IInfo(d) for d in self._dmd.ZenUsers.dashboards()])

        # 2. Dashboards defined on my groups or all groups (if I'm manager)
        if checkPermission(ZEN_MANAGE_DMD, self._dmd):
            groupsNames = user.getAllGroupSettingsNames()
        else:
            groupsNames = user.getUserGroupSettingsNames()

        for name in groupsNames:
            group = self._dmd.ZenUsers.getGroupSettings(name)
            dashboards.extend([IInfo(d) for d in group.dashboards()])

        # 3. My dashboards
        dashboards.extend([IInfo(d) for d in user.dashboards()])

        return dashboards
Пример #4
0
    def _buildMetric(self, context, dp, cf, extraRpn="", format=""):
        datasource = dp.datasource()
        dsId = datasource.id
        info = IInfo(dp)

        # find out our aggregation function
        agg = AGGREGATION_MAPPING.get(cf.lower(), cf.lower())
        rateOptions = info.getRateOptions()
        tags = self._buildTagsFromContextAndMetric(context, dsId)
        metricname = dp.name()
        key = self._get_key_from_tags(tags)
        search = _devname_pattern.match(key)
        if search:
            prefix = search.groups()[0]
            metricname = metrics.ensure_prefix(prefix, metricname)
        metric = dict(metric=metricname,
                      aggregator=agg,
                      rpn=extraRpn,
                      format=format,
                      tags=tags,
                      rate=info.rate,
                      name=context.getResourceKey() + "|" + dp.name())
        if rateOptions:
            metric['rateOptions'] = rateOptions
        return metric
Пример #5
0
    def test_Info(self):
        """Assert that API Info are functioning."""
        from Products.Zuul.infos.component import ComponentInfo
        from Products.Zuul.infos.device import DeviceInfo

        from ZenPacks.zenoss.ZPLTest1.APIC import APIC, APICInfo
        from ZenPacks.zenoss.ZPLTest1.FabricNode import FabricNode, FabricNodeInfo

        apic1 = APIC('apic1')
        apic1_info = IInfo(apic1)

        self.assert_superclasses(apic1_info, (
            DeviceInfo,
            APICInfo,
        ))

        node1 = FabricNode('node1')
        node1.role = 'controller'
        node1_info = IInfo(node1)

        self.assert_superclasses(node1_info, (
            ComponentInfo,
            FabricNodeInfo,
        ))

        self.assertTrue(
            hasattr(node1_info, 'role'),
            "{info!r} has no {attribute!r} attribute".format(info=node1_info,
                                                             attribute='role'))

        self.assertTrue(
            node1_info.role == 'controller',
            "{info!r}.{attribute!r} != {value!r}".format(info=node1_info,
                                                         attribute='role',
                                                         value='controller'))
Пример #6
0
    def _buildMetric(self, context, dp, cf, extraRpn="", format=""):
        datasource = dp.datasource()
        dsId = datasource.id
        info = IInfo(dp)

        # find out our aggregation function
        agg = AGGREGATION_MAPPING.get(cf.lower(), cf.lower())
        rateOptions = info.getRateOptions()
        tags = self._buildTagsFromContextAndMetric(context, dsId)
        metricname = dp.name()
        key = self._get_key_from_tags(tags)
        search = _devname_pattern.match(key)
        if search:
            prefix = search.groups()[0]
            metricname = metrics.ensure_prefix(prefix, metricname)
        metric = dict(
            metric=metricname,
            aggregator=agg,
            rpn=extraRpn,
            format=format,
            tags=tags,
            rate=info.rate,
            name=context.getResourceKey() + "|" + dp.name()
        )
        if rateOptions:
            metric['rateOptions'] = rateOptions
        return metric
Пример #7
0
    def testInfoAdapters(self):
        """Make sure that our Info adapters are wired correctly."""

        from Products.Zuul.interfaces import IInfo
        from ZenPacks.training.NetBotz.Enclosure import Enclosure
        from ZenPacks.training.NetBotz.TemperatureSensor import TemperatureSensor

        device_info = IInfo(self.device)
        self.assertTrue(hasattr(device_info, 'temp_sensor_count'))

        enclosure1 = Enclosure('enclosure1')
        self.device.enclosures._setObject(enclosure1.id, enclosure1)
        enclosure1 = self.device.enclosures._getOb(enclosure1.id)

        enclosure1_info = IInfo(enclosure1)
        self.assertTrue(hasattr(enclosure1_info, 'enclosure_status'))
        self.assertEquals(enclosure1_info.temperature_sensor_count, 0)

        sensor1 = TemperatureSensor('sensor1')
        enclosure1.temperature_sensors._setObject(sensor1.id, sensor1)
        sensor1 = enclosure1.temperature_sensors._getOb(sensor1.id)

        sensor1_info = IInfo(sensor1)
        self.assertTrue(hasattr(sensor1_info, 'port'))
        self.assertEquals(sensor1_info.enclosure.id, 'enclosure1')
    def saveDashboard(self, data):
        """
        Need to do the following
        1. Rename the dashboard if the name changed
        2. move the dashboard if the context changed
        3. call regular set info to save properties
        """
        # will fail if the uid isn't passed in
        uid = data['uid']
        del data['uid']
        d = self._getObject(uid)

        # 1. rename dashboard
        if data['newId'] != d.id:
            IInfo(d).rename(data['newId'])

        # 2. move object if context changed
        newContext = self._getContext(data['contextUid'])
        if uid == "/zport/dmd/ZenUsers/dashboards/default" and data[
                'contextUid'] != "/zport/dmd/ZenUsers":
            raise Exception("Can't assign default portlet to the user %s",
                            newContext)
        del data['contextUid']
        if newContext != d.getContext():
            oldContext = d.getContext()
            oldContext.dashboards._delObject(d.id)
            d = aq_base(d)
            newContext.dashboards._setObject(d.id, d)
            # fetch the object in the new context
            d = newContext.dashboards._getOb(d.id)

        # 3. save the rest of the data
        self.setInfo(d.getPrimaryId(), data)
        return IInfo(d)
Пример #9
0
    def getTree(self, id):
        """
        Returns the tree structure of the application and collector
        hierarchy.

        @type  id: string
        @param id: Id of the root node of the tree to be returned
        @rtype:   [dictionary]
        @return:  Object representing the tree
        """
        try:
            appfacade = self._getFacade()
            monitorfacade = Zuul.getFacade("monitors", self.context)
            nodes = [ITreeNode(m) for m in monitorfacade.query()]
            for monitor in nodes:
                apps = appfacade.queryMonitorDaemons(monitor.name)
                for app in apps:
                    monitor.addChild(IInfo(app))
            apps = appfacade.queryMasterDaemons()
            for app in apps:
                nodes.append(IInfo(app))
            return Zuul.marshal(nodes)
        except URLError as e:
            log.exception(e)
            return DirectResponse.fail("Error fetching daemons list: " +
                                       str(e.reason))
Пример #10
0
 def makeInfo(notification):
     notificationInfo = IInfo(notification)
     notificationInfo.subscriptions = [
         {"uuid": trigger["uuid"], "name": trigger["name"]}
         for trigger in triggers
         if trigger["uuid"] in notification.subscriptions
     ]
     return notificationInfo
Пример #11
0
 def testInfoObjectServiceKeysCatalog(self):
     """
     Makes sure that when we update a service keys the changes are
     reflected in the catalog
     """
     id = manage_addIpServiceClass(self.dmd.Services.serviceclasses, 'test')
     svc  = self.dmd.Services.serviceclasses._getOb(id)
     info = IInfo(svc)
     info.serviceKeys = "pepe"
     results = self.dmd.Services.find('pepe')
     self.assertTrue(results)
Пример #12
0
 def getThresholdDetails(self, uid):
     """
     @param String uid: the id of the threshold
     @returns IThresholdInfo
     """
     threshold = self._getObject(uid)
     template = threshold.rrdTemplate()
     info = IInfo(threshold)
     # don't show the "selected one" in the list of avaialble
     info.allDataPoints = [point for point in template.getRRDDataPointNames()]
     return info
Пример #13
0
 def testInfoObjectServiceKeysCatalog(self):
     """
     Makes sure that when we update a service keys the changes are
     reflected in the catalog
     """
     id = manage_addIpServiceClass(self.dmd.Services.serviceclasses, 'test')
     svc = self.dmd.Services.serviceclasses._getOb(id)
     info = IInfo(svc)
     info.serviceKeys = "pepe"
     results = self.dmd.Services.find('pepe')
     self.assertTrue(results)
Пример #14
0
 def getValue(obj):
     key = obj.getPrimaryPath()
     if key in savedValues:
         value = savedValues[key]
     else:
         value = getattr(IInfo(obj), orderby)
         if callable(value):
             value = value()
         # if an info object is returned then sort by the name
         if IInfo.providedBy(value):
             value = value.name.lower()
         savedValues[key] = value
     return value
Пример #15
0
 def getMultiGraphReports(self, uid='/zport/dmd/Reports'):
     results = []
     obj = self._getObject(uid)
     searchresults = self._search_catalog(obj, MultiGraphReport)
     for brain in searchresults:
         try:
             org = brain.getObject()
             info = IInfo(org)
             info.fullOrganizerName = self._getFullOrganizerName(org)
             results.append(info)
         except:
             # error unbraining the object just skip it
             pass
     return results
Пример #16
0
 def getTopLevelOrganizers(self, uid):
     results = []
     obj = self._getObject(uid or ZPORT_DMD)
     searchresults = ICatalogTool(obj).search(DeviceOrganizer)
     for brain in searchresults:
         try:
             org = brain.getObject()
             info = IInfo(org)
             info.fullOrganizerName = self._getFullOrganizerName(org)
             results.append(info)
         except:
             # error unbraining the object just skip it
             pass
     return results
Пример #17
0
    def getTopLevelOrganizers(self, uid):
        results = []
        obj = self._getObject(uid or ZPORT_DMD)
        searchresults = self._search_catalog(obj, types=DeviceOrganizer)

        for brain in searchresults:
            try:
                org = brain.getObject()
                info = IInfo(org)
                info.fullOrganizerName = self._getFullOrganizerName(org)
                results.append(info)
            except:
                # error unbraining the object just skip it
                pass
        return results
Пример #18
0
    def getDevices(self,
                   uid=None,
                   start=0,
                   limit=50,
                   sort='name',
                   dir='ASC',
                   params=None,
                   hashcheck=None):
        params = params if params else {}
        # Passing a key that's not an index in the catalog will
        # cause a serious performance penalty.  Remove 'status' from
        # the 'params' parameter before passing it on.
        statuses = params.pop('status', None)
        brains = self.getDeviceBrains(uid, start, limit, sort, dir, params,
                                      hashcheck)

        # ZEN-10057 - Handle the case of empty results for a filter with no matches
        if not brains:
            return SearchResults(iter([]), 0, '0')

        devices = [IInfo(obj) for obj in imap(unbrain, brains) if obj]

        if statuses is not None and len(statuses) < 3:
            devices = [d for d in devices if d.status in statuses]

        uuids = set(dev.uuid for dev in devices)
        if uuids:
            zep = getFacade('zep', self._dmd)
            severities = zep.getEventSeverities(uuids)
            for device in devices:
                device.setEventSeverities(severities[device.uuid])

        return SearchResults(iter(devices), brains.total, brains.hash_)
Пример #19
0
    def _filterComponents(self, comps, keys, query):
        """
        Returns a list of components where one of the attributes in keys contains
        the query (case-insensitive).

        @type  comps: SearchResults
        @param comps: All the Components for this query
        @type  keys: List
        @param keys: List of strings of fields that we are filtering on
        @type  query: String
        @param query: Search Term
        @rtype:   List
        @return:  List of Component Info objects that match the query
        """
        results = []
        query = query.lower()
        for comp in comps:
            keep = False
            for key in keys:
                # non searchable fields
                if key in ('uid', 'uuid', 'events', 'status', 'severity'):
                    continue
                val = getattr(comp, key, None)
                if not val:
                    continue
                if callable(val):
                    val = val()
                if IInfo.providedBy(val):
                    val = val.name
                if query in str(val).lower():
                    keep = True
                    break
            if keep:
                results.append(comp)
        return results
 def getUserCommands(self, uid=None):
     """
     gets all the user commands associated with a device or devices
     """
     obj = self._getObject(uid)
     userCommands = (IInfo(s) for s in obj.getUserCommands())        
     return userCommands      
Пример #21
0
    def exportNotifications(self, notifications):
        configs = []
        junkColumns = ('id', 'newId', 'uid', 'inspector_type', 'meta_type')
        for notificationInfo in notifications:
            config = marshal(notificationInfo)
            for item in junkColumns:
                if item in config:
                    del config[item]

            contentsTab = self._extractNotificationContentInfo(config)
            del config['content']
            config.update(contentsTab)

            config['recipients'] = [r['label'] for r in config['recipients']]
            config['subscriptions'] = [
                x['name'] for x in config['subscriptions']
            ]

            windows = []
            for window in notificationInfo._object.windows():
                winconfig = marshal(IInfo(window))
                for witem in ('meta_type', 'newId', 'id', 'inspector_type',
                              'uid'):
                    del winconfig[witem]
                windows.append(winconfig)
            config['windows'] = windows

            configs.append(config)
        return configs
Пример #22
0
 def getInfo(self, uid):
     """
     @param uid unique identifier of an object
     @returns the info object as identified by the UID
     """
     obj = self._getObject(uid)
     return IInfo(obj)
Пример #23
0
    def getIpAddresses(self, limit=0, start=0, sort='ipAddressAsInt', dir='DESC',
              params=None, uid=None, criteria=()):
        infos = []
        cat = ICatalogTool(self._getObject(uid))
        reverse = dir=='DESC'

        brains = cat.search("Products.ZenModel.IpAddress.IpAddress",
                            start=start, limit=limit,
                            orderby=sort, reverse=reverse)

        for brain in brains:
            infos.append(IInfo(unbrain(brain)))

        devuuids = set(info.device.uuid for info in infos if info.device)

        # get ping severities
        zep = getFacade('zep')
        pingSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Ping)
        self._assignPingStatuses(infos, pingSeverities)

        # get snmp severities
        snmpSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Snmp)
        self._assignSnmpStatuses(infos, snmpSeverities)

        return SearchResults(infos, brains.total, brains.hash_)
Пример #24
0
    def _filterComponents(self, comps, keys, query):
        """
        Returns a list of components where one of the attributes in keys contains
        the query (case-insensitive).

        @type  comps: SearchResults
        @param comps: All the Components for this query
        @type  keys: List
        @param keys: List of strings of fields that we are filtering on
        @type  query: String
        @param query: Search Term
        @rtype:   List
        @return:  List of Component Info objects that match the query
        """
        results = []
        query = query.lower()
        for comp in comps:
            keep = False
            for key in keys:
                # non searchable fields
                if key in ('uid', 'uuid', 'events', 'status', 'severity'):
                    continue
                val = getattr(comp, key, None)
                if not val:
                    continue
                if callable(val):
                    val = val()
                if IInfo.providedBy(val):
                    val = val.name
                if query in str(val).lower():
                    keep = True
                    break
            if keep:
                results.append(comp)
        return results
Пример #25
0
    def getNotifications(self):
        self.synchronize()

        user = getSecurityManager().getUser()
        for n in self.notificationPermissions.findNotifications(
                user,
                self._getNotificationManager().getChildNodes()):
            yield IInfo(n)
Пример #26
0
 def getInfos(self, uids, keys):
     facade = self._getFacade()
     devices = [facade._getObject(uid) for uid in uids]
     infos = [
         IInfo(dev) for dev in devices
         if dev.checkRemotePerm(ZEN_VIEW, dev)
     ]
     return DirectResponse.succeed(data=Zuul.marshal(infos, keys=keys))
Пример #27
0
 def getApplicationConfigFiles(self, id):
     """
     Returns all the configuration files for an application
     """
     facade = self._getFacade()
     info = IInfo(facade.get(id))
     files = info.configFiles
     return DirectResponse.succeed(data=Zuul.marshal(files))
Пример #28
0
    def setMonitor(self, uids, monitor=False):
        comps = imap(self._getObject, uids)
        for comp in comps:
            IInfo(comp).monitor = monitor
            # update the componentSearch catalog
            comp.index_object(idxs=('monitored', ))

            # update the global catalog as well
            notify(IndexingEvent(comp, idxs=('monitored', )))
Пример #29
0
 def getOid(self, oid):
     try:
         node = next(iter(self.api.getOidList(oid)), None)
     except Exception as ex:
         log.warn("Error while looking up OID '%s': %s", oid, ex)
         node = None
     if node is None:
         return DirectResponse.fail()
     return DirectResponse.succeed(info=Zuul.marshal(IInfo(node)))
Пример #30
0
 def getCollector(self, collectorString):
     """
     Get a collector by name
     @type  collectorString: string
     @param collectorString: name of collector to return
     """
     facade = Zuul.getFacade('monitors', self.context)
     collector = IInfo(facade.get(collectorString))
     return DirectResponse.succeed(data=Zuul.marshal(collector))
Пример #31
0
 def updateConfigFiles(self, id, configFiles):
     """
     Updates the configuration files for an application specified by id.
     The configFiles parameters is an array of dictionaries of the form:
     {
         filename: "blah",
         contents: "line 1\nline 2\n..."
     }
     The filename parameter serves as the "id" of each configFile
     passed in.
     """
     facade = self._getFacade()
     info = IInfo(facade.get(id))
     for f in configFiles:
         configFile = info.getConfigFileByFilename(f['filename'])
         if configFile:
             configFile.content = f['content']
     return DirectResponse.succeed()
Пример #32
0
 def getSubOrganizers(self, uid):
     results = []
     obj = self._getObject(uid or "/zport/dmd")
     searchresults = ICatalogTool(obj).search(DeviceOrganizer)
     if isinstance(obj, DeviceOrganizer):
         info = IInfo(obj)
         info.fullOrganizerName = self._getFullOrganizerName(obj)
         results.append(info)
     for brain in searchresults:
         try:
             org = brain.getObject()
             info = IInfo(org)
             info.fullOrganizerName = self._getFullOrganizerName(org)
             results.append(info)
         except:
             # error unbraining the object just skip it
             pass
     return results
Пример #33
0
 def addNewInstance(self, params=None):
     """
     Add new event class mapping for the current context
     @params.evclass = the event class this instance is associated with
     @params.instanceID = the instance ID
     """
     obj = self._getObject(params['evclass'])
     result = IInfo(obj.createInstance(params['newName']))
     return result
 def getNotification(self, uid):
     user = getSecurityManager().getUser()
     notification = self._getObject(uid)
     if self.notificationPermissions.userCanViewNotification(user, notification):
         log.debug('getting notification: %s' % notification)
         return IInfo(notification)
     else:
         log.warning('User not authorized to view this notification: %s' % uid)
         raise Exception('User not authorized to view this notification: %s' % uid)
Пример #35
0
 def componentSortKey(parent):
     val = getattr(parent, sort)
     if val:
         if isinstance(val, list):
             val = val[0]
         if callable(val):
             val = val()
         if IInfo.providedBy(val):
             val = val.name
     return val
Пример #36
0
 def getDeviceIssues(self):
     zep = getFacade('zep', self._dmd)
     manager = IGUIDManager(self._dmd)
     deviceSeverities = zep.getDeviceIssuesDict()
     zem = self.context.dmd.ZenEventManager
     devdata = []
     # only get the first 100 since this is just the portlet
     for uuid in deviceSeverities.keys()[:100]:
         dev = manager.getObject(uuid)
         if dev and isinstance(dev, Device):
             if (not zem.checkRemotePerm(ZEN_VIEW, dev)
                 or dev.productionState < zem.prodStateDashboardThresh
                 or dev.priority < zem.priorityDashboardThresh):
                 continue
             severities = deviceSeverities[uuid]
             info = IInfo(dev)
             info.setEventSeverities(severities)
             devdata.append(info)
     return devdata
Пример #37
0
 def componentSortKey(parent):
     val = getattr(parent, sort)
     if val:
         if isinstance(val, list):
             val = val[0]
         if callable(val):
             val = val()
         if IInfo.providedBy(val):
             val = val.name
     return pad_numeric_values_for_indexing(val)
Пример #38
0
 def _organizerInfo(self, objs):
     result = []
     for obj in objs:
         info = IInfo(obj)
         result.append(
             dict(name=info.name,
                  uid=info.uid,
                  uuid=info.uuid,
                  path=info.path))
     return result
Пример #39
0
    def _buildMetric(self, context, dp, cf, extraRpn="", format=""):
        datasource = dp.datasource()
        dsId = datasource.id
        info = IInfo(dp)

        # find out our aggregation function
        agg = AGGREGATION_MAPPING.get(cf.lower(), cf.lower())
        rateOptions = info.getRateOptions()
        tags = self._buildTagsFromContextAndMetric(context, dsId)
        metric = dict(
            metric=dp.id,
            aggregator=agg,
            rpn=extraRpn,
            format=format,
            tags=tags,
            rate=info.rate,
            name=context.getUUID() + "_" + dp.id
        )
        if rateOptions:
            metric['rateOptions'] = rateOptions
        return metric
Пример #40
0
 def getValue(obj):
     key = obj.getPrimaryPath()
     if key in savedValues:
         value = savedValues[key]
     else:
         value = getattr(IInfo(obj), orderby)
         if callable(value):
             value = value()
         # if an info object is returned then sort by the name
         if IInfo.providedBy(value):
             value = value.name.lower()
         savedValues[key] = value
     return value
Пример #41
0
 def getSubOrganizers(self, uid):
     results = []
     uid = uid or ZPORT_DMD
     obj = self._getObject(uid)
     if uid == ZPORT_DMD:
         searchresults = ICatalogTool(obj).search(DeviceOrganizer, paths=PATHS)
     else:
         searchresults = ICatalogTool(obj).search(DeviceOrganizer)
     if isinstance(obj, DeviceOrganizer):
         info = IInfo(obj)
         info.fullOrganizerName = self._getFullOrganizerName(obj)
         results.append(info)
     for brain in searchresults:
         try:
             org = brain.getObject()
             info = IInfo(org)
             info.fullOrganizerName = self._getFullOrganizerName(org)
             results.append(info)
         except:
             # error unbraining the object just skip it
             pass
     return results
Пример #42
0
    def _buildMetric(self, context, dp, cf, extraRpn="", format=""):
        datasource = dp.datasource()
        dsId = datasource.id
        info = IInfo(dp)

        # find out our aggregation function
        agg = AGGREGATION_MAPPING.get(cf.lower(), cf.lower())
        rateOptions = info.getRateOptions()
        tags = self._buildTagsFromContextAndMetric(context, dsId)
        metricname = dp.name()
        key = self._get_key_from_tags(tags)
        search = _devname_pattern.match(key)
        if search:
            metricname = metrics.ensure_prefix(context.getMetricMetadata(), metricname)
        name = context.getResourceKey() + "|" + dp.name()
        metric = dict(
            metric=metricname,
            aggregator=agg,
            tags=tags,
            rate=info.rate,
            name=name
        )
        combined_metric = [metric]
        if rateOptions:
            metric['rateOptions'] = rateOptions
        if extraRpn:
            metric['emit'] = 'false'
            metric['name'] = "{}-raw".format(dp.name())
            new_metric = dict(
                expression="rpn:{}-raw,{}".format(dp.name(), extraRpn),
                format=format,
                name=name
            )
            combined_metric.append(new_metric)
        else:
            metric['format'] = format
        return combined_metric