Skip to content

Commit

Permalink
Merge pull request python-diamond#47 from jaingaurav/config
Browse files Browse the repository at this point in the history
Config file fixes
  • Loading branch information
kormoc committed Jan 4, 2015
2 parents aa252ca + 26a4da6 commit fc59d15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/diamond/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def run(self):
sys.exit(1)

handlers = self.config['server'].get('handlers')
handlers = handlers.split(',')
handlers = map(str.strip, handlers)
if isinstance(handlers, basestring):
handlers = [handlers]

# Prevent the Queue Handler from being a normal handler
if 'diamond.handler.queue.QueueHandler' in handlers:
Expand Down
15 changes: 8 additions & 7 deletions src/diamond/utils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load_handlers(config, handler_names):
try:
# Load Handler Class
cls = load_dynamic_class(handler, Handler)
cls_name = cls.__class__.__name__
cls_name = cls.__name__

# Initialize Handler config
handler_config = configobj.ConfigObj()
Expand All @@ -75,12 +75,13 @@ def load_handlers(config, handler_names):
handler_config.merge(config['handlers'][cls_name])

# Check for config file in config directory
configfile = os.path.join(
config['server']['handlers_config_path'],
cls_name) + '.conf'
if os.path.exists(configfile):
# Merge Collector config file
handler_config.merge(configobj.ConfigObj(configfile))
if 'handlers_config_path' in config['server']:
configfile = os.path.join(
config['server']['handlers_config_path'],
cls_name) + '.conf'
if os.path.exists(configfile):
# Merge Collector config file
handler_config.merge(configobj.ConfigObj(configfile))

# Initialize Handler class
h = cls(handler_config)
Expand Down
50 changes: 26 additions & 24 deletions src/diamond/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ def load_config(configfile):
config['handlers'] = configobj.ConfigObj()

if 'handlers_config_path' in config['server']:
for cfgfile in os.listdir(config['server']['handlers_config_path']):
cfgfile = os.path.join(config['server']['handlers_config_path'],
cfgfile)
cfgfile = os.path.abspath(cfgfile)
if not cfgfile.endswith(config_extension):
continue
filename = os.path.basename(cfgfile)
handler = os.path.splitext(filename)[0]

if handler not in config['handlers']:
config['handlers'][handler] = configobj.ConfigObj(cfgfile)
else:
handlers_config_path = config['server']['handlers_config_path']
if os.path.exists(handlers_config_path):
for cfgfile in os.listdir(handlers_config_path):
cfgfile = os.path.join(handlers_config_path, cfgfile)
cfgfile = os.path.abspath(cfgfile)
if not cfgfile.endswith(config_extension):
continue
filename = os.path.basename(cfgfile)
handler = os.path.splitext(filename)[0]

if handler not in config['handlers']:
config['handlers'][handler] = configobj.ConfigObj()

newconfig = configobj.ConfigObj(cfgfile)
config['handlers'][handler].merge(newconfig)

Expand All @@ -85,18 +86,19 @@ def load_config(configfile):
config['collectors'] = configobj.ConfigObj()

if 'collectors_config_path' in config['server']:
for cfgfile in os.listdir(config['server']['collectors_config_path']):
cfgfile = os.path.join(config['server']['collectors_config_path'],
cfgfile)
cfgfile = os.path.abspath(cfgfile)
if not cfgfile.endswith(config_extension):
continue
filename = os.path.basename(cfgfile)
collector = os.path.splitext(filename)[0]

if collector not in config['collectors']:
config['collectors'][collector] = configobj.ConfigObj(cfgfile)
else:
collectors_config_path = config['server']['handlers_config_path']
if os.path.exists(collectors_config_path):
for cfgfile in os.listdir(collectors_config_path):
cfgfile = os.path.join(collectors_config_path, cfgfile)
cfgfile = os.path.abspath(cfgfile)
if not cfgfile.endswith(config_extension):
continue
filename = os.path.basename(cfgfile)
collector = os.path.splitext(filename)[0]

if collector not in config['collectors']:
config['collectors'][collector] = configobj.ConfigObj()

newconfig = configobj.ConfigObj(cfgfile)
config['collectors'][collector].merge(newconfig)

Expand Down

0 comments on commit fc59d15

Please sign in to comment.