예제 #1
0
    def _mapColumnsToDatapoints(self, dmd):
        """
        Create a map of columns->alias/datapoint pairs.  For each
        column we need both the datapoint/alias-- the datapoint to
        retrieve the rrd data and the alias to execute the alias
        formula to transform that data (to get the correct units).

        Non-perf columns will be mapped to None
        """
        def getAliasName(column):
            return column.getAliasName()

        # First, split the columns into perf and non-perf columns
        columns = self.getColumns()
        aliasColumns = filter(
                lambda x: getAliasName(x) is not None, columns
            )

        columnDatapointsMap = {}

        # Map columns to empty list to ensure that there are placeholders
        # for all columns even if there are not aliased datapoints.
        for column in columns:
            columnDatapointsMap[column] = []

        # Fourth, match up the columns with the corresponding alias/datapoint
        # pairs
        for column in aliasColumns:
            columnDatapointsMap[column] = list(getDataPointsByAliases(dmd, [column.getAliasName()]))

        return columnDatapointsMap
예제 #2
0
    def _mapColumnsToDatapoints(self, dmd):
        """
        Create a map of columns->alias/datapoint pairs.  For each
        column we need both the datapoint/alias-- the datapoint to
        retrieve the rrd data and the alias to execute the alias
        formula to transform that data (to get the correct units).

        Non-perf columns will be mapped to None
        """
        def getAliasName(column):
            return column.getAliasName()

        # First, split the columns into perf and non-perf columns
        columns = self.getColumns()
        aliasColumns = filter(lambda x: getAliasName(x) is not None, columns)

        columnDatapointsMap = {}

        # Map columns to empty list to ensure that there are placeholders
        # for all columns even if there are not aliased datapoints.
        for column in columns:
            columnDatapointsMap[column] = []

        # Fourth, match up the columns with the corresponding alias/datapoint
        # pairs
        for column in aliasColumns:
            columnDatapointsMap[column] = list(
                getDataPointsByAliases(dmd, [column.getAliasName()]))

        return columnDatapointsMap
예제 #3
0
    def testGetDatapointByAliases_EmptyAliases(self):
        template = createTemplate(self.dmd, 'template5')
        addAliases(
            template, {
                ('alias5_1', 'form5_1'): ('ds1', 'dp1'),
                ('alias5_2', 'form5_2'): ('ds2', 'dp1'),
                ('alias5_3', 'form5_2'): ('ds2', 'dp1')
            })

        dps = getDataPointsByAliases(self.dmd, [])
        self.assert_(len(list(dps)) == 0)
        removeTemplate(self.dmd, 'template5')
예제 #4
0
 def testGetDatapointByAliases_EmptyAliases(self):
     template = createTemplate( self.dmd, 'template5' )
     addAliases( template, 
                      {
                       ('alias5_1', 'form5_1'):('ds1', 'dp1'),
                       ( 'alias5_2', 'form5_2' ) : ('ds2', 'dp1'),
                       ( 'alias5_3', 'form5_2' ) : ('ds2', 'dp1'  )
                       } )
     
     dps = getDataPointsByAliases( self.dmd, [] )
     self.assert_( len( list( dps ) ) == 0 )
     removeTemplate( self.dmd, 'template5')
예제 #5
0
    def testGetDatapointsByAliases_NoMatch(self):
        #Templates with no aliases
        template = createTemplate(self.dmd, 'template1')
        addAliases(
            template, {
                ('alias1_1', 'form1_1'): ('ds1', 'dp1'),
                ('alias1_2', 'form1_2'): ('ds2', 'dp1'),
                ('alias1_3', 'form1_3'): ('ds2', 'dp1')
            })

        dps = getDataPointsByAliases(self.dmd, ['badalias1', 'badalias2'])
        self.assert_(len(list(dps)) == 0)
        removeTemplate(self.dmd, 'template1')
예제 #6
0
 def testGetDatapointsByAliases_NoMatch(self):
     #Templates with no aliases
     template = createTemplate( self.dmd, 'template1' )
     addAliases( template, 
                      {
                       ('alias1_1', 'form1_1'):('ds1', 'dp1'),
                       ( 'alias1_2', 'form1_2' ) : ('ds2', 'dp1'),
                       ( 'alias1_3', 'form1_3' ) : ('ds2', 'dp1'  )
                       } )
     
     dps = getDataPointsByAliases( self.dmd, ['badalias1','badalias2'] )
     self.assert_( len( list( dps ) ) == 0 )
     removeTemplate( self.dmd, 'template1')
예제 #7
0
    def testGetDatapointsByAliases_OneAliasPerDatapoint(self):
        #Templates with dps with one alias
        template = createTemplate(self.dmd, 'template2')
        aliasMap = {
            ('alias2_1', 'form2_1'): ('ds1', 'dp1'),
            ('alias2_2', 'form2_2'): ('ds2', 'dp1')
        }
        addAliases(template, aliasMap)
        searchAliases = ['alias2_1', 'alias2_2']
        gen = getDataPointsByAliases(self.dmd, searchAliases)
        aliasDatapointMap = dict(gen)
        self.assert_(len(aliasDatapointMap.values()) == 2)
        for foundAlias, datapoint in aliasDatapointMap.iteritems():
            self.assert_(foundAlias.id in searchAliases)
            assertAliasDatapointInMap(self, foundAlias, datapoint, aliasMap)

        removeTemplate(self.dmd, 'template2')
예제 #8
0
    def testGetDatapointsByAliases_OneAliasPerDatapoint(self):
        #Templates with dps with one alias
        template = createTemplate( self.dmd, 'template2' )
        aliasMap = {
                    ('alias2_1', 'form2_1') : ('ds1', 'dp1'),
                    ('alias2_2', 'form2_2') : ('ds2', 'dp1')
                    }
        addAliases( template, aliasMap )
        searchAliases = ['alias2_1','alias2_2']
        gen = getDataPointsByAliases( self.dmd, searchAliases )
        aliasDatapointMap = dict( gen )
        self.assert_( len( aliasDatapointMap.values() ) == 2)
        for foundAlias, datapoint in aliasDatapointMap.iteritems():
            self.assert_( foundAlias.id in searchAliases )
            assertAliasDatapointInMap( self, foundAlias, datapoint, aliasMap )

        removeTemplate( self.dmd, 'template2' )
예제 #9
0
    def testGetDatapointByAliases_MatchDatapointName(self):
        template = createTemplate(self.dmd, 'template4')
        aliasMap = {
            ('alias4_1', 'form4_1'): ('ds1', 'dp1'),
            ('alias4_2', 'form4_2'): ('ds2', 'dp1'),
            ('alias4_3', 'form4_3'): ('ds2', 'dp1')
        }
        addAliases(template, aliasMap)

        gen = getDataPointsByAliases(self.dmd, ['dp3'])

        aliasDps = list(gen)
        self.assert_(len(aliasDps) == 2)
        for alias, dp in aliasDps:
            self.assert_(alias is None)
            self.assert_(dp.id == 'dp3')
            self.assert_(dp.datasource().id in ['ds1', 'ds3'])

        removeTemplate(self.dmd, 'template4')
예제 #10
0
 def testGetDatapointByAliases_MatchDatapointName(self):        
     template = createTemplate( self.dmd, 'template4' )
     aliasMap = {
                 ('alias4_1', 'form4_1') : ('ds1', 'dp1'),
                 ('alias4_2', 'form4_2') : ('ds2', 'dp1'),
                 ('alias4_3', 'form4_3') : ('ds2', 'dp1')
                 }
     addAliases( template, aliasMap )
     
     gen = getDataPointsByAliases( self.dmd, ['dp3'] )
     
     aliasDps = list( gen )
     self.assert_(len( aliasDps ) == 2)
     for alias, dp in aliasDps:
         self.assert_( alias is None )
         self.assert_( dp.id == 'dp3' )
         self.assert_( dp.datasource().id in ['ds1','ds3'] )
           
     removeTemplate( self.dmd, 'template4' )
예제 #11
0
    def testGetDatapointsByAliases_MultipleAliasesPerDatapoint(self):
        #Templates with dps with multiple aliases
        #import pydevd;pydevd.settrace()
        template = createTemplate(self.dmd, 'template3')
        aliasMap = {
            ('alias3_1', 'form3_1'): ('ds1', 'dp1'),
            ('alias3_2', 'form3_2'): ('ds2', 'dp1'),
            ('alias3_3', 'form3_3'): ('ds2', 'dp1')
        }
        addAliases(template, aliasMap)

        searchAliases = ['alias3_1', 'alias3_2']
        gen = getDataPointsByAliases(self.dmd, searchAliases)

        aliasDatapointMap = dict(gen)
        self.assert_(len(aliasDatapointMap.values()) == 2)
        for foundAlias, datapoint in aliasDatapointMap.iteritems():
            self.assert_(foundAlias.id in searchAliases)
            assertAliasDatapointInMap(self, foundAlias, datapoint, aliasMap)

        removeTemplate(self.dmd, 'template3')
예제 #12
0
    def testGetDatapointsByAliases_MultipleAliasesPerDatapoint(self):
        #Templates with dps with multiple aliases
        #import pydevd;pydevd.settrace()
        template = createTemplate( self.dmd, 'template3' )
        aliasMap = {
                    ('alias3_1', 'form3_1') : ('ds1', 'dp1'),
                    ('alias3_2', 'form3_2') : ('ds2', 'dp1'),
                    ('alias3_3', 'form3_3') : ('ds2', 'dp1')
                    }
        addAliases( template, aliasMap )
        
        searchAliases = ['alias3_1','alias3_2']
        gen = getDataPointsByAliases( self.dmd, searchAliases )

        aliasDatapointMap = dict( gen )
        self.assert_( len( aliasDatapointMap.values() ) == 2)
        for foundAlias, datapoint in aliasDatapointMap.iteritems():
            self.assert_( foundAlias.id in searchAliases )
            assertAliasDatapointInMap( self, foundAlias, datapoint, aliasMap )

        removeTemplate( self.dmd, 'template3' )
예제 #13
0
    def _mapColumnsToDatapoints(self, dmd):
        """
        Create a map of columns->alias/datapoint pairs.  For each
        column we need both the datapoint/alias-- the datapoint to
        retrieve the rrd data and the alias to execute the alias
        formula to transform that data (to get the correct units).

        Non-perf columns will be mapped to None
        """
        def getAliasName(column):
            return column.getAliasName()

        # First, split the columns into perf and non-perf columns
        columns = self.getColumns()
        aliasColumns = filter(
                lambda x: getAliasName(x) is not None, columns
            )

        # Second, map the alias names to their columns
        aliasColumnMap = \
                dict(zip(map(getAliasName, aliasColumns), aliasColumns))

        columnDatapointsMap = {}

        # Map columns to empty list to ensure that there are placeholders
        # for all columns even if there are not aliased datapoints.
        for column in columns:
            columnDatapointsMap[column] = []

        # Fourth, match up the columns with the corresponding alias/datapoint
        # pairs
        aliasDatapointPairs = \
                getDataPointsByAliases(dmd, aliasColumnMap.keys())
        for alias, datapoint in aliasDatapointPairs:
            # If the alias-datapoint pair is missing the alias, then
            # the column's aliasName was really the datapoint name.
            column = aliasColumnMap[alias.id if alias else datapoint.id]
            columnDatapointsMap[column].append((alias, datapoint))

        return columnDatapointsMap