Ignore:
Timestamp:
03/21/13 15:32:44 (11 years ago)
Author:
ramonb
Message:
  • some helper functions getting config values
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4/parse_ganglia.py

    r696 r697  
    133133
    134134            #print 'keep: %s' %t
    135             self.conf_lijst.append( t )
     135            self.conf_lijst.append( self.removeQuotes(t) )
    136136
    137137    def getConfLijst( self ):
     
    190190                    return (new_dict, count)
    191191
    192     def getConfDict( self ):
    193 
    194         return self.conf_dict
    195192
    196193    def makeConfDict( self ):
     
    248245        #print 'leaving makeConfDict(): conf dict size %d' %len( self.conf_dict )
    249246
     247    def checkConfDict( self ):
     248
     249        if len( self.conf_lijst ) == 0:
     250
     251            raise Exception("Something went wrong generating conf list for %s" %self.file_name )
     252
     253        if len( self.conf_dict ) == 0:
     254
     255            self.makeConfDict()
     256
     257    def getConfDict( self ):
     258
     259        self.checkConfDict()
     260        return self.conf_dict
     261
     262    def getUdpSendChannels( self ):
     263
     264        self.checkConfDict()
     265        return self.conf_dict[ 'udp_send_channel' ]
     266
     267    def getSectionLastOption( self, section, option ):
     268
     269        """
     270        Get last option set in a config section that could be set multiple times in multiple (include) files.
     271
     272        i.e.: getSectionLastOption( 'globals', 'send_metadata_interval' )
     273        """
     274
     275        self.checkConfDict()
     276        value = None
     277
     278        if not self.conf_dict.has_key( section ):
     279
     280            return None
     281
     282        # Could be set multiple times in multiple (include) files: get last one set
     283        for c in self.conf_dict[ section ]:
     284
     285                if c.has_key( option ):
     286
     287                    cluster_name = c[ option ][0]
     288
     289        return cluster_name
     290
     291    def getClusterName( self ):
     292
     293        return self.getSectionLastOption( 'cluster', 'name' )
     294
    250295GMOND_LOCATION = '/etc/ganglia/gmond.conf'
    251296
     
    257302
    258303pprint.pprint( g.getConfDict(), width=1 )
     304
     305print g.getClusterName()
     306print g.getUdpSendChannels()
    259307
    260308print 'exiting..'
Note: See TracChangeset for help on using the changeset viewer.