Skip to content

Commit

Permalink
Merge pull request #658 from XTAIN/config-dir
Browse files Browse the repository at this point in the history
Support for config merging from specified directory
  • Loading branch information
kormoc committed Jul 24, 2014
2 parents c3fd88b + 2a3356d commit 7715a89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions conf/diamond.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,16 @@ args = ('/var/log/diamond/diamond.log', 'midnight', 1, 7)
format = [%(asctime)s] [%(threadName)s] %(message)s
datefmt =

################################################################################
### Options for config merging
# [configs]
# path = "/etc/diamond/configs/"
# extension = ".conf"
#-------------------------------------------------------------------------------
# Example:
# /etc/diamond/configs/net.conf
# [collectors]
#
# [[NetworkCollector]]
# enabled = True

10 changes: 8 additions & 2 deletions src/diamond/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ def __init__(self, config):

def load_config(self):
"""
Load the full config
Load the full config / merge splitted configs if configured
"""

configfile = os.path.abspath(self.config['configfile'])
config = configobj.ConfigObj(configfile)
config['configfile'] = self.config['configfile']

try:
for cfgfile in os.listdir(config['configs']['path']):
if cfgfile.endswith(config['configs']['extension']):
newconfig = configobj.ConfigObj(config['configs']['path'] + cfgfile)
config.merge(newconfig)
except KeyError:
pass
self.config = config

def load_handler(self, fqcn):
Expand Down

0 comments on commit 7715a89

Please sign in to comment.