예제 #1
0
 def _talesEval(cs, dev, extr):
     if not (cs.startswith('string:') or cs.startswith('python:')):
         cs = 'string:%s' % cs
     cs = talesEval(cs, device, extr)
     if '${' in cs:
         cs = talesEval(cs, device, extr)
     return cs
 def _talesEval(cs, dev, extr):
     if not (cs.startswith('string:') or cs.startswith('python:')):
         cs = 'string:%s'%cs
     cs = talesEval(cs, device, extr)
     if '${' in cs:
         cs = talesEval(cs, device, extr)
     return cs
예제 #3
0
    def discoverDevices(self, uid):
        """
        Discover devices on input subnetwork
        """
        ip = '/'.join(self._dmd.restrictedTraverse(uid).getPrimaryPath()[4:])
        orgroot = self._root.restrictedTraverse(uid).getNetworkRoot()

        organizer = orgroot.getOrganizer(ip)
        if organizer is None:
            log.error("Couldn't obtain a network entry for '%s' "
                        "-- does it exist?" % ip)
            return False

        zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
        if zDiscCommand:
            from Products.ZenUtils.ZenTales import talesEval
            cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
        else:
            cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
            if getattr(organizer, "zSnmpStrictDiscovery", False):
                cmd += ["--snmp-strict-discovery"]
            if getattr(organizer, "zPreferSnmpNaming", False):
                cmd += ["--prefer-snmp-naming"]
        zd = binPath('zendisc')
        zendiscCmd = [zd] + cmd[1:]
        return self._dmd.JobManager.addJob(SubprocessJob,
           description="Discover devices in network %s" % organizer.getNetworkName(),
           args=(zendiscCmd,))
예제 #4
0
 def getMinval(self, context):
     """Build the min value for this threshold.
     """
     minval = None
     if self.minval:
         minval = talesEval("python:"+self.minval, context)
     return minval
        def toDict(device, ds, dps=[]):
            '''marshall the fields from the datasource into a dictionary and
            ignore everything that is not a primitive'''

            vals = {}
            vals['dps'] = []
            vals['dptypes'] = []
            for key, val in ds.__dict__.items():
                if isinstance(val, XmlRpcService.PRIMITIVES):
                    if isinstance(val, basestring) and '$' in val:
                        val = talesEval('string:%s' % (val, ), device)
                    vals[key] = val

            for dp in dps:
                vals['dps'].append(dp.id)
                vals['dptypes'].append(dp.rrdtype)

            # add zproperties
            for propertyId in device.propertyIds():
                value = device.getProperty(propertyId)

                # _millis can't be serialized because it is long, so
                # we skip it to avoid an XML-RPC serialization error
                if isinstance(value, DateTime.DateTime):
                    continue

                vals[propertyId] = value

            vals['device'] = device.id
            vals['manageIp'] = device.manageIp

            return vals
예제 #6
0
 def _getDsDatapoints(self, comp, ds, perfServer, dpnames, sql=''):
     """
     Given a component a data source, gather its data points
     """
     points = []
     if comp == comp.device():
         component_name = ds.getComponent(comp)
     elif callable(getattr(comp, 'name', None)):
         component_name = comp.name()
     else:
         component_name = getattr(comp, 'id', '')
     basepath = comp.rrdPath()
     for dp in ds.getRRDDataPoints():
         dpnames.add(dp.name())
         dpc = DataPointConfig()
         dpc.id = dp.id
         for alias in dp.aliases():
             aliasId = alias.id.strip().lower()
             if dpc.alias and ' %s ' % aliasId not in sql: continue
             dpc.alias = aliasId
             formula = getattr(alias, 'formula', None)
             if not formula: continue
             dpc.expr = talesEval("string:%s" % formula,
                                  comp,
                                  extra={'now': 'now'})
         if not dpc.alias:
             dpc.alias = dp.id.strip().lower()
         dpc.component = component_name
         dpc.rrdPath = "/".join((basepath, dp.name()))
         dpc.rrdType = dp.rrdtype
         dpc.rrdCreateSql = dp.getRRDCreateCommand(perfServer)
         dpc.rrdMin = dp.rrdmin
         dpc.rrdMax = dp.rrdmax
         points.append(dpc)
     return points
예제 #7
0
    def discoverDevices(self, uid):
        """
        Discover devices on input subnetwork
        """
        ip = '/'.join(self._dmd.restrictedTraverse(uid).getPrimaryPath()[4:])
        orgroot = self._root.restrictedTraverse(uid).getNetworkRoot()

        organizer = orgroot.getOrganizer(ip)
        if organizer is None:
            log.error("Couldn't obtain a network entry for '%s' "
                      "-- does it exist?" % ip)
            return False

        zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
        if zDiscCommand:
            from Products.ZenUtils.ZenTales import talesEval
            cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
        else:
            cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
            if getattr(organizer, "zSnmpStrictDiscovery", False):
                cmd += ["--snmp-strict-discovery"]
            if getattr(organizer, "zPreferSnmpNaming", False):
                cmd += ["--prefer-snmp-naming"]
        zd = binPath('zendisc')
        zendiscCmd = [zd] + cmd[1:]
        return self._dmd.JobManager.addJob(
            SubprocessJob,
            description="Discover devices in network %s" %
            organizer.getNetworkName(),
            args=(zendiscCmd, ))
 def _getDsDatapoints(self, comp, ds, perfServer, dpnames, sql=''):
     """
     Given a component a data source, gather its data points
     """
     points = []
     if comp == comp.device():
         component_name = ds.getComponent(comp)
     elif callable(getattr(comp, 'name', None)):
         component_name = comp.name()
     else:
         component_name = getattr(comp, 'id', '')
     basepath = comp.rrdPath()
     for dp in ds.getRRDDataPoints():
         dpnames.add(dp.name())
         dpc = DataPointConfig()
         dpc.id = dp.id
         for alias in dp.aliases():
             aliasId = alias.id.strip().lower()
             if dpc.alias and ' %s '%aliasId not in sql: continue
             dpc.alias = aliasId
             formula = getattr(alias, 'formula', None)
             if not formula: continue
             dpc.expr=talesEval("string:%s"%formula,comp,extra={'now':'now'})
         if not dpc.alias:
             dpc.alias = dp.id.strip().lower()
         dpc.component = component_name
         dpc.rrdPath = "/".join((basepath, dp.name()))
         dpc.rrdType = dp.rrdtype
         dpc.rrdCreateSql = dp.getRRDCreateCommand(perfServer)
         dpc.rrdMin = dp.rrdmin
         dpc.rrdMax = dp.rrdmax
         points.append(dpc)
     return points
    def evaluateDataSourceExpression(self, context, propName, readablePropName):
        """
        Return back a sane value from evaluation of an expression.

        @paramter context: device or component object
        @type context: device or component object
        @paramter propName: name of the threshold property to evaluate
        @type propName: string
        @paramter readablePropName: property name for displaying in error messages
        @type readablePropName: string
        @returns: numeric
        @rtype: numeric
        """
        value = getattr(self, propName, None)
        if value:
            try:
                express = "python:%s" % value
                evaluated = talesEval(express, context)
                value = evaluated
            except:
                msg= "User-supplied Python expression (%s) for %s caused error: %s" % (
                           value, readablePropName, self.dsnames)
                log.error(msg)
                raise pythonThresholdException(msg)
                value = None
        return nanToNone(value)
예제 #10
0
    def evaluateDataSourceExpression(self, context, propName, readablePropName):
        """
        Return back a sane value from evaluation of an expression.

        @paramter context: device or component object
        @type context: device or component object
        @paramter propName: name of the threshold property to evaluate
        @type propName: string
        @paramter readablePropName: property name for displaying in error messages
        @type readablePropName: string
        @returns: numeric
        @rtype: numeric
        """
        value = getattr(self, propName, None)
        if value:
            try:
                express = "python:%s" % value
                evaluated = talesEval(express, context)
                value = evaluated
            except:
                msg= "User-supplied Python expression (%s) for %s caused error: %s" % (
                    value, readablePropName, self.dsnames)
                log.error(msg)
                raise pythonThresholdException(msg)
                value = None
            return nanToNone(value)
예제 #11
0
def processTalSource(source, **kwargs):
    """
    This function is used to parse fields made available to actions that allow
    for TAL expressions.
    """
    if not kwargs.get('dev'):
        hasDevReference = re.search(DEVICE_TAL, source)
        if hasDevReference:
            attributes = hasDevReference.groups()
            log.error("The TALES string '%s' references ${dev/xxx} %s,"
                          " but no Zenoss device exists (use ${evt/xxx} fields instead?)",
                          source, attributes)
            message = NO_ZEN_DEVICE % source
            raise TalesMissingZenossDevice(message)

    try:
        context = kwargs.get('here')
        return talesEval(source, context, kwargs)
    except CompilerError as ex:
        message = "%s: %s" % (ex, source)
        log.error("%s context = %s data = %s", message, context, kwargs)
        raise BadTalesExpresssion(message)
    except InvalidTalesException:
        message = BAD_TALES % source
        log.error("%s context = %s data = %s", message, context, kwargs)
        raise BadTalesExpresssion(message)
예제 #12
0
        def toDict(device, ds, dps=[]):
            '''marshall the fields from the datasource into a dictionary and
            ignore everything that is not a primitive'''

            vals = {}
            vals['dps'] = []
            vals['dptypes'] = []
            for key, val in ds.__dict__.items():
                if isinstance(val, XmlRpcService.PRIMITIVES):
                    if isinstance(val, basestring) and '$' in val:
                        val = talesEval('string:%s' % (val, ), device)
                    vals[key] = val

            for dp in dps:
                vals['dps'].append(dp.id)
                vals['dptypes'].append(dp.rrdtype)

            # add zproperties
            for propertyId in device.propertyIds():
                value = device.getProperty(propertyId)

                # _millis can't be serialized because it is long, so
                # we skip it to avoid an XML-RPC serialization error
                if isinstance(value, DateTime.DateTime):
                    continue

                vals[propertyId] = value

            vals['device'] = device.id
            vals['manageIp'] = device.manageIp

            return vals
예제 #13
0
 def copyProperties(self, device, ds):
     for prop in [p['id'] for p in ds._properties]:
         try:
             value = getattr(ds, prop)
         except AttributeError:
             continue
         if str(value).find('$') >= 0:
             value = talesEval('string:%s' % (value,), device, {'dev': device})
         setattr(self, prop, value)
예제 #14
0
 def __call__(self, device, component=None, extra=None, value=None):
     kw = dict(device=device, component=component, value=value)
     kw.update(self._extraContext)
     if extra is not None:
         kw.update(extra)
     value = None
     try:
         value = talesEval(self._talesExpression, device, kw)
     except InvalidTalesException, e:
         log.info(e)
예제 #15
0
 def __call__(self, device, component=None, extra=None, value=None):
     kw = dict(device=device, component=component, value=value)
     kw.update(self._extraContext)
     if extra is not None:
         kw.update(extra)
     value = None
     try:
         value = talesEval(self._talesExpression, device, kw)
     except InvalidTalesException, e:
         log.info(e)
예제 #16
0
    def getGraphCmds(self,
                     context,
                     rrdDir,
                     multiid=-1,
                     upToPoint=None,
                     includeSetup=True,
                     includeThresholds=True,
                     prefix='',
                     cmds=None,
                     idxOffset=0):
        """build the graph opts for a single rrdfile"""
        from Products.ZenUtils.ZenTales import talesEval
        if not cmds:
            cmds = []
        if includeSetup:
            cmds += self.graphsetup()

        # Have to draw thresholds before data so that thresholds won't
        # obscure data (especially if threshold uses TICK)
        if includeThresholds:
            threshGps = [
                gp for gp in self.getThresholdGraphPoints()
                if upToPoint is None or gp.sequence < upToPoint
            ]
            if threshGps:
                for index, gp in enumerate(threshGps):
                    try:
                        cmds = gp.getGraphCmds(cmds, context, rrdDir,
                                               self.hasSummary,
                                               index + idxOffset, multiid,
                                               prefix)
                    except (KeyError, NameError) as e:
                        cmds.append('COMMENT: UNKNOWN VALUE IN '
                                    'GRAPHPOINT %s\: %s' % (gp.id, str(e)))
        gpList = [
            gp for gp in self.getGraphPoints(includeThresholds=False)
            if upToPoint is None or gp.sequence < upToPoint
        ]
        for index, gp in enumerate(gpList):
            try:
                cmds = gp.getGraphCmds(cmds, context, rrdDir, self.hasSummary,
                                       index + idxOffset, multiid, prefix)
            except (KeyError, NameError) as e:
                cmds.append('COMMENT: UNKNOWN VALUE IN GRAPHPOINT '
                            '%s\: %s' % (gp.id, str(e)))
        if self.custom and includeSetup and not upToPoint:
            try:
                res = talesEval("string:" + str(self.custom), context)
            except (KeyError, NameError) as e:
                res = 'COMMENT:UNKNOWN VALUE IN CUSTOM COMMANDS\: %s' % str(e)
            cmds.extend(l for l in res.split('\n') if l.strip())
            #if self.hasSummary:
            #    cmds = self.addSummary(cmds)

        return cmds
예제 #17
0
 def getDevices(self):
     """Return the device list for this report.
     """
     devs = self.getDmdRoot("Devices")
     if self.path != "/": devs = devs.getOrganizer(self.path)
     devlist = devs.getSubDevices()
     if self.deviceQuery:
         try:
             return [ dev for dev in devlist \
                         if talesEval("python:"+self.deviceQuery, dev) ]
         except Exception, e:
             return e
예제 #18
0
 def getDevices(self):
     """Return the device list for this report.
     """
     devs = self.getDmdRoot("Devices")
     if self.path != "/": devs = devs.getOrganizer(self.path)
     devlist = devs.getSubDevices()
     if self.deviceQuery:
         try:
             return [ dev for dev in devlist \
                         if talesEval("python:"+self.deviceQuery, dev) ]
         except Exception, e:
             return e
예제 #19
0
def getWbemComponentConfig(transports, comp, queries, datapoints):
    threshs = []
    basepath = comp.rrdPath()
    perfServer = comp.device().getPerformanceServer()
    for templ in comp.getRRDTemplates():
        names = []
        datasources = []
        for tr in transports:
            datasources.extend(templ.getRRDDataSources(tr))
        for ds in datasources:
            if not ds.enabled:
                continue
            transport, classname, kb, namespace = ds.getInstanceInfo(comp)
            if transport != transports[0]:
                continue
            qid = comp.id + "_" + templ.id + "_" + ds.id
            datapoints[qid] = []
            properties = {}
            compname = comp.meta_type == "Device" and "" or comp.id
            for dp in ds.getRRDDataPoints():
                if len(dp.aliases()) > 0:
                    alias = dp.aliases()[0].id.strip()
                    expr = talesEval("string:%s" % dp.aliases()[0].formula, comp, extra={"now": "now"})
                else:
                    alias = dp.id.strip()
                    expr = None
                if alias not in properties:
                    properties[alias] = (dp.id,)
                else:
                    properties[alias] = properties[alias] + (dp.id,)
                dpname = dp.name()
                names.append(dpname)
                datapoints[qid].append(
                    (
                        dp.id,
                        compname,
                        expr,
                        "/".join((basepath, dpname)),
                        dp.rrdtype,
                        dp.getRRDCreateCommand(perfServer),
                        (dp.rrdmin, dp.rrdmax),
                    )
                )
            queries = sortQuery(queries, qid, (classname, kb, namespace, properties))
        for threshold in templ.thresholds():
            if not threshold.enabled:
                continue
            for ds in threshold.dsnames:
                if ds not in names:
                    continue
                threshs.append(threshold.createThresholdInstance(comp))
                break
    return threshs
예제 #20
0
 def getGraphCmds(self, context, rrdfile, template):
     """build the graph opts for a single rrdfile"""
     cmds = self.graphsetup()
     if self.custom:
         cmds = self.buildCustomDS(cmds, rrdfile, template)
         res = talesEval("string:"+self.custom, context)
         cmds.extend(res.split("\n"))
         if self.hasSummary:
              cmds = self.addSummary(cmds)
     else:
         cmds = self.buildDS(cmds, rrdfile, template, self.summary)
     cmds = self.thresholds(cmds, context, template)
     return cmds
 def copyProperties(self, device, ds):
     """
     copy the properties from the datasouce and set them
     as attributes
     """
     for propName in [prop['id'] for prop in ds._properties]:
         value = getattr(ds, propName)
         if str(value).find('$') >= 0:
             value = talesEval('string:%s' % (value,), device)
         if propName == 'authenticate':
             if value:
                 value = str(value).lower().capitalize()
             value = bool(value)
         setattr(self, propName, value)
예제 #22
0
 def getPointval(self, context):
     """Build the point value for this threshold.
     """
     pointval = None
     if self.pointval:
         try:
             pointval = talesEval("python:" + self.pointval, context)
         except:
             msg= "User-supplied Python expression (%s) for point value caused error: %s" % \
                        ( self.pointval,  self.dsnames )
             log.error(msg)
             raise pythonThresholdException(msg)
             pointval = None
     return pointval
 def getPointval(self, context):
     """Build the point value for this threshold.
     """
     pointval = None
     if self.pointval:
         try:
             pointval = talesEval("python:"+self.pointval, context)
         except:
             msg= "User-supplied Python expression (%s) for point value caused error: %s" % \
                        ( self.pointval,  self.dsnames )
             log.error( msg )
             raise pythonThresholdException(msg)
             pointval = None
     return pointval
예제 #24
0
 def copyProperties(self, device, ds):
     """
     copy the properties from the datasouce and set them
     as attributes
     """
     for propName in [prop['id'] for prop in ds._properties]:
         value = getattr(ds, propName)
         if str(value).find('$') >= 0:
             value = talesEval('string:%s' % (value, ), device)
         if propName == 'authenticate':
             if value:
                 value = str(value).lower().capitalize()
             value = bool(value)
         setattr(self, propName, value)
예제 #25
0
 def getMaxval(self, context):
     """Build the max value for this threshold.
     """
     maxval = None
     if self.maxval:
         try:
             express = "python:%s" % self.maxval
             maxval = talesEval(express, context)
         except:
             msg = ("User-supplied Python expression (%s) for "
                    "maximum value caused error: %s") % (self.maxval,
                                                         self.dsnames)
             log.error(msg)
             raise pythonThresholdException(msg)
             maxval = None
     return nanToNone(maxval)
예제 #26
0
 def getHystM(self, context):
     """
     """
     queueSize = 0
     if self.queueSize:
         try:
             express = "python:%s" % self.queueSize
             queueSize = talesEval(express, context)
         except:
             msg = ("User-supplied Python expression (%s) for "
                    "hysteresis M value caused error: %s") % (
                        self.queueSize, self.dsnames)
             log.error(msg)
             raise pythonThresholdException(msg)
             queueSize = 0
     return queueSize
예제 #27
0
 def getHystK(self, context):
     """
     """
     goodCount = 0
     if self.goodCount:
         try:
             express = "python:%s" % self.goodCount
             goodCount = talesEval(express, context)
         except:
             msg = ("User-supplied Python expression (%s) for "
                    "hysteresis K value caused error: %s") % (
                        self.goodCount, self.dsnames)
             log.error(msg)
             raise pythonThresholdException(msg)
             goodCount = 0
     return goodCount
예제 #28
0
    def discoverDevices(self, organizerPaths=None, REQUEST=None):
        """
        Load a device into the database connecting its major relations
        and collecting its configuration.
        """
        xmlrpc = isXmlRpc(REQUEST)

        if not organizerPaths:
            if xmlrpc: return 1
            return self.callZenScreen(REQUEST)

        zDiscCommand = "empty"

        from Products.ZenUtils.ZenTales import talesEval

        orgroot = self.getNetworkRoot()
        for organizerName in organizerPaths:
            organizer = orgroot.getOrganizer(organizerName)
            if organizer is None:
                if xmlrpc: return 1  # XML-RPC error
                log.error("Couldn't obtain a network entry for '%s' "
                          "-- does it exist?" % organizerName)
                continue

            zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
            if zDiscCommand:
                cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
            else:
                cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
                if getattr(organizer, "zSnmpStrictDiscovery", False):
                    cmd += ["--snmp-strict-discovery"]
                if getattr(organizer, "zPreferSnmpNaming", False):
                    cmd += ["--prefer-snmp-naming"]
            zd = binPath('zendisc')
            zendiscCmd = [zd] + cmd[1:]
            status = self.dmd.JobManager.addJob(
                SubprocessJob,
                description="Discover devices in network %s" %
                organizer.getNetworkName(),
                args=(zendiscCmd, ))

        log.info('Done')

        if REQUEST and not xmlrpc:
            REQUEST.RESPONSE.redirect('/zport/dmd/JobManager/joblist')

        if xmlrpc: return 0
예제 #29
0
    def discoverDevices(self, organizerPaths=None, REQUEST = None):
        """
        Load a device into the database connecting its major relations
        and collecting its configuration.
        """
        xmlrpc = isXmlRpc(REQUEST)

        if not organizerPaths:
            if xmlrpc: return 1
            return self.callZenScreen(REQUEST)

        zDiscCommand = "empty"

        from Products.ZenUtils.ZenTales import talesEval

        orgroot = self.getNetworkRoot()
        for organizerName in organizerPaths:
            organizer = orgroot.getOrganizer(organizerName)
            if organizer is None:
                if xmlrpc: return 1 # XML-RPC error
                log.error("Couldn't obtain a network entry for '%s' "
                            "-- does it exist?" % organizerName)
                continue

            zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
            if zDiscCommand:
                cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
            else:
                cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
                if getattr(organizer, "zSnmpStrictDiscovery", False):
                    cmd += ["--snmp-strict-discovery"]
                if getattr(organizer, "zPreferSnmpNaming", False):
                    cmd += ["--prefer-snmp-naming"]
            zd = binPath('zendisc')
            zendiscCmd = [zd] + cmd[1:]
            status = self.dmd.JobManager.addJob(SubprocessJob,
                description="Discover devices in network %s" % organizer.getNetworkName(),
                args=(zendiscCmd,))

        log.info('Done')

        if REQUEST and not xmlrpc:
            REQUEST.RESPONSE.redirect('/zport/dmd/JobManager/joblist')

        if xmlrpc: return 0
예제 #30
0
def getWbemComponentConfig(transports, comp, queries, datapoints):
    threshs = []
    basepath = comp.rrdPath()
    perfServer = comp.device().getPerformanceServer()
    for templ in comp.getRRDTemplates():
        names = []
        datasources = []
        for tr in transports:
            datasources.extend(templ.getRRDDataSources(tr))
        for ds in datasources:
            if not ds.enabled: continue
            transport, classname, kb, namespace = ds.getInstanceInfo(comp)
            if transport != transports[0]: continue
            qid = comp.id + "_" + templ.id + "_" + ds.id
            datapoints[qid] = []
            properties = {}
            compname = comp.meta_type == "Device" and "" or comp.id
            for dp in ds.getRRDDataPoints():
                if len(dp.aliases()) > 0:
                    alias = dp.aliases()[0].id.strip()
                    expr = talesEval("string:%s"%dp.aliases()[0].formula, comp,
                                                            extra={'now':'now'})
                else:
                    alias = dp.id.strip()
                    expr = None
                if alias not in properties: properties[alias] = (dp.id,)
                else: properties[alias] = properties[alias] + (dp.id,)
                dpname = dp.name()
                names.append(dpname)
                datapoints[qid].append((dp.id,
                                        compname,
                                        expr,
                                        "/".join((basepath, dpname)),
                                        dp.rrdtype,
                                        dp.getRRDCreateCommand(perfServer),
                                        (dp.rrdmin, dp.rrdmax)))
            queries = sortQuery(queries,qid,(classname,kb,namespace,properties))
        for threshold in templ.thresholds():
            if not threshold.enabled: continue
            for ds in threshold.dsnames:
                if ds not in names: continue
                threshs.append(threshold.createThresholdInstance(comp))
                break
    return threshs
예제 #31
0
def getSqlComponentConfig(comp, queries, datapoints):
    threshs = []
    try:
        basepath = comp.rrdPath()
        perfServer = comp.device().getPerformanceServer()
    except: return []
    for templ in comp.getRRDTemplates():
        names = []
        for ds in templ.getRRDDataSources():
            if not ds.enabled: continue
            if not isinstance(ds, DataSource): continue
            qi = ds.getQueryInfo(comp)
            if not qi: continue
            qid = comp.id + "_" + templ.id + "_" + ds.id
            datapoints[qid] = []
            columns = {}
            compname = comp.meta_type == "Device" and "" or comp.id
            for dp in ds.getRRDDataPoints():
                if len(dp.aliases()) > 0:
                    alias = dp.aliases()[0].id.strip()
                    expr = talesEval("string:%s"%dp.aliases()[0].formula, comp,
                                                            extra={'now':'now'})
                else:
                    alias = dp.id.strip()
                    expr = None
                if alias not in columns: columns[alias] = (dp.id,)
                else: columns[alias] = columns[alias] + (dp.id,)
                dpname = dp.name()
                names.append(dpname)
                datapoints[qid].append((dp.id,
                                        compname,
                                        expr,
                                        "/".join((basepath, dpname)),
                                        dp.rrdtype,
                                        dp.getRRDCreateCommand(perfServer),
                                        (dp.rrdmin, dp.rrdmax)))
            queries = sortQuery(queries, qid, qi + (columns,))
        for threshold in templ.thresholds():
            if not threshold.enabled: continue
            for ds in threshold.dsnames:
                if ds not in names: continue
                threshs.append(threshold.createThresholdInstance(comp))
                break
    return threshs
예제 #32
0
def getSqlComponentConfig(comp, queries, datapoints):
    threshs = []
    try:
        basepath = comp.rrdPath()
        perfServer = comp.device().getPerformanceServer()
    except:
        return []
    for templ in comp.getRRDTemplates():
        names = []
        for ds in templ.getRRDDataSources():
            if not ds.enabled: continue
            if not isinstance(ds, DataSource): continue
            qi = ds.getQueryInfo(comp)
            if not qi: continue
            qid = comp.id + "_" + templ.id + "_" + ds.id
            datapoints[qid] = []
            columns = {}
            compname = comp.meta_type == "Device" and "" or comp.id
            for dp in ds.getRRDDataPoints():
                if len(dp.aliases()) > 0:
                    alias = dp.aliases()[0].id.strip()
                    expr = talesEval("string:%s" % dp.aliases()[0].formula,
                                     comp,
                                     extra={'now': 'now'})
                else:
                    alias = dp.id.strip()
                    expr = None
                if alias not in columns: columns[alias] = (dp.id, )
                else: columns[alias] = columns[alias] + (dp.id, )
                dpname = dp.name()
                names.append(dpname)
                datapoints[qid].append((dp.id, compname, expr, "/".join(
                    (basepath, dpname)), dp.rrdtype,
                                        dp.getRRDCreateCommand(perfServer),
                                        (dp.rrdmin, dp.rrdmax)))
            queries = sortQuery(queries, qid, qi + (columns, ))
        for threshold in templ.thresholds():
            if not threshold.enabled: continue
            for ds in threshold.dsnames:
                if ds not in names: continue
                threshs.append(threshold.createThresholdInstance(comp))
                break
    return threshs
 def _getDsDatapoints(self, comp, ds, perfServer):
     """
     Given a component a data source, gather its data points
     """
     points = []
     component_name = ds.getComponent(comp)
     basepath = comp.rrdPath()
     for dp in ds.getRRDDataPoints():
         alias = (dp.aliases() or [dp])[0]
         formula = getattr(alias, 'formula', None)
         dpc = DataPointConfig()
         dpc.id = dp.id
         if formula:
             dpc.expr=talesEval("string:%s"%formula,comp,extra={'now':'now'})
         dpc.alias = alias.id.strip().lower()
         dpc.component = component_name
         dpc.rrdPath = "/".join((basepath, dp.name()))
         dpc.rrdType = dp.rrdtype
         dpc.rrdCreateSql = dp.getRRDCreateCommand(perfServer)
         dpc.rrdMin = dp.rrdmin
         dpc.rrdMax = dp.rrdmax
         points.append(dpc)
     return points
예제 #34
0
 def _getComponents(self, device, componentPath):
     componentPath = 'here/%s' % componentPath
     try:
         return talesEval(componentPath, device)
     except AttributeError:
         return []
 def talesEvalStr(self, value, **kwargs):
     if value.startswith("python:"):
         return talesEval(value, self, extra=kwargs)
     else:
         return talesEvalStr(value, self, extra=kwargs)
예제 #36
0
    def _createDeviceProxy(self, device):
        proxy = CollectorConfigService._createDeviceProxy(self, device)

        # for now, every device gets a single configCycleInterval based upon
        # the collector's winCycleInterval configuration which is typically
        # located at dmd.Monitors.Performance._getOb('localhost').
        # TODO: create a zProperty that allows for individual device schedules
        proxy.configCycleInterval = self._prefs.perfsnmpCycleInterval
        proxy.datapoints = []
        proxy.thresholds = []
        queries = {}
        log.debug('device: %s', device)
        try: perfServer = device.getPerformanceServer()
        except: return None
        evtOrgNames = self.dmd.Events.Status.getOrganizerNames()
        for comp in [device] + device.getMonitoredComponents():
            compName = ""
            compType = ""
            if not isinstance(comp, Device):
                compName = comp.id
                if comp.__class__.__name__ in evtOrgNames:
                    compType = comp.__class__.__name__
                elif comp.meta_type in evtOrgNames:
                    compType = comp.meta_type
            try: basepath = comp.rrdPath()
            except: continue
            for templ in comp.getRRDTemplates():
                dpnames = []
                for ds in templ.getRRDDataSources():
                    if not (isinstance(ds, DataSource) and ds.enabled):continue
                    sql, sqlp, kbs, cs = ds.getQueryInfo(comp)
                    if not sql: continue
                    if sqlp and '_process where' in sql.lower(): sql = sqlp
                    tn = '/'.join([device.id, comp.id, templ.id, ds.id])
                    aliases = set()
                    sortkey = (cs,)
                    for dp in ds.getRRDDataPoints():
                        dpname = dp.name()
                        dpnames.append(dpname)
                        alias = (dp.aliases() or [dp])[0]
                        aname = alias.id.strip().lower()
                        formula = getattr(alias, 'formula', None)
                        expr = formula and talesEval("string:%s"%alias.formula,
                                            comp, extra={'now':'now'}) or None
                        aliases.add(aname)
                        proxy.datapoints.append((sortkey, tn, dp.id, aname,
                                (compName, compType),
                                expr,
                                "/".join((basepath, dpname)),
                                dp.rrdtype,
                                dp.getRRDCreateCommand(perfServer),
                                (dp.rrdmin, dp.rrdmax)))
                    queries.setdefault(sortkey, {})[tn] = (sqlp, kbs, cs,
                                                dict(zip(aliases,aliases)), sql)

                dpn = set(dpnames)
                for thr in templ.thresholds():
                    if not (thr.enabled and dpn & set(thr.dsnames)): continue
                    proxy.thresholds.append(thr.createThresholdInstance(comp))

        proxy.queries = queries
        if not queries:
            log.debug("Device %s skipped because there are no datasources",
                          device.getId())
            return None
        return proxy
 def runTest(self):
     manager = self.dmd.Devices
     talesEval('python: here.setZenProperty("foo", "bar")', manager)
     result = talesEval('python: here.getProperty("foo")', manager)
     self.assertEqual('bar', result)
 def runTest(self):
     manager = self.dmd.Devices
     talesEval('python: here.setZenProperty("foo", "bar")', manager)
     result = talesEval('python: here.getProperty("foo")', manager)
     self.assertEqual('bar', result)
예제 #39
0
 def copyProperties(self, device, ds):
     for prop in [p['id'] for p in ds._properties]:
         value = getattr(ds, prop)
         if str(value).find('$') >= 0:
             value = talesEval('string:%s' % (value,), device)
         setattr(self, prop, value)
                    except (KeyError, NameError), e:
                        cmds.append('COMMENT: UNKNOWN VALUE IN '
                            'GRAPHPOINT %s\: %s' % (gp.id, str(e)))
        gpList = [gp for gp in self.getGraphPoints(includeThresholds=False)
                    if upToPoint is None or gp.sequence < upToPoint]
        for index, gp in enumerate(gpList):
            try:
                cmds = gp.getGraphCmds(cmds, context, rrdDir, 
                                        self.hasSummary, index+idxOffset,
                                        multiid, prefix)
            except (KeyError, NameError), e:
                cmds.append('COMMENT: UNKNOWN VALUE IN GRAPHPOINT '
                        '%s\: %s' % (gp.id, str(e)))
        if self.custom and includeSetup and not upToPoint:
            try:
                res = talesEval("string:"+str(self.custom), context)
            except (KeyError, NameError), e:
                res = 'COMMENT:UNKNOWN VALUE IN CUSTOM COMMANDS\: %s' % str(e)
            cmds.extend(l for l in res.split('\n') if l.strip())
            #if self.hasSummary:
            #    cmds = self.addSummary(cmds)

        return cmds


    def getRRDVariables(self, upToPoint=None):
        """ Return list of rrd variable names that are defined by DEF, CDEF
        or VDEF statements in the rrd commands.  If upToPoint is not None then
        only consider statements generated by graphoints where
        sequence < upToPoint
        """
예제 #41
0
 def _getComponents(self, device, componentPath):
     componentPath = 'here/%s' % componentPath
     try:
         return talesEval(componentPath, device)
     except AttributeError:
         return []
예제 #42
0
 def _getComponents(self, device, componentPath):
     componentPath = "here/%s" % componentPath
     try:
         return talesEval(componentPath, device)
     except:
         return []
 def talesEvalStr(self, value, **kwargs):
     if value.startswith("python:"):
         return talesEval(value, self, extra=kwargs)
     else:
         return talesEvalStr(value, self, extra=kwargs)
예제 #44
0
                        cmds.append('COMMENT: UNKNOWN VALUE IN '
                                    'GRAPHPOINT %s\: %s' % (gp.id, str(e)))
        gpList = [
            gp for gp in self.getGraphPoints(includeThresholds=False)
            if upToPoint is None or gp.sequence < upToPoint
        ]
        for index, gp in enumerate(gpList):
            try:
                cmds = gp.getGraphCmds(cmds, context, rrdDir, self.hasSummary,
                                       index + idxOffset, multiid, prefix)
            except (KeyError, NameError), e:
                cmds.append('COMMENT: UNKNOWN VALUE IN GRAPHPOINT '
                            '%s\: %s' % (gp.id, str(e)))
        if self.custom and includeSetup and not upToPoint:
            try:
                res = talesEval("string:" + str(self.custom), context)
            except (KeyError, NameError), e:
                res = 'COMMENT:UNKNOWN VALUE IN CUSTOM COMMANDS\: %s' % str(e)
            cmds.extend(l for l in res.split('\n') if l.strip())
            #if self.hasSummary:
            #    cmds = self.addSummary(cmds)

        return cmds

    def getRRDVariables(self, upToPoint=None):
        """ Return list of rrd variable names that are defined by DEF, CDEF
        or VDEF statements in the rrd commands.  If upToPoint is not None then
        only consider statements generated by graphoints where
        sequence < upToPoint
        """
        cmds = self.getFakeGraphCmds(upToPoint=upToPoint)