Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
    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
Ejemplo n.º 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
Ejemplo n.º 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'))
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 8
0
    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)
Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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_)
Ejemplo n.º 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      
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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_)
Ejemplo n.º 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
Ejemplo n.º 25
0
    def getNotifications(self):
        self.synchronize()

        user = getSecurityManager().getUser()
        for n in self.notificationPermissions.findNotifications(
                user,
                self._getNotificationManager().getChildNodes()):
            yield IInfo(n)
Ejemplo 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))
Ejemplo n.º 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))
Ejemplo n.º 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', )))
Ejemplo n.º 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)))
Ejemplo n.º 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))
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 34
0
 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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