Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Config] Fix deprecated nagios logic left broken after refactor
Browse files Browse the repository at this point in the history
tmichelet committed Feb 22, 2016
1 parent 090417a commit 59cc583
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -781,7 +781,7 @@ def _all_configs_paths(osname, agentConfig):
if not any('nagios' in config for config in itertools.chain(*all_configs)):
# check if it's configured in datadog.conf the old way
if any([nagios_key in agentConfig for nagios_key in NAGIOS_OLD_CONF_KEYS]):
all_configs.append('deprecated_nagios')
all_configs.append(['deprecated/nagios'])


return all_configs
@@ -806,13 +806,13 @@ def _checks_places(agentConfig, osname):
places.append(lambda name: os.path.join(checksd_path, '%s.py' % name))
return places

def _validate_config(config_path, check_name):
def _validate_config(config_path, check_name, agentConfig):

if config_path == 'deprecated_nagios':
if config_path == 'deprecated/nagios':
log.warning("Configuring Nagios in datadog.conf is deprecated "
"and will be removed in a future version. "
"Please use conf.d")
check_config = {'instances':[dict((key, agentConfig[key]) for key in agentConfig if key in NAGIOS_OLD_CONF_KEYS)]}
check_config = {'instances':[dict((key, value) for (key, value) in agentConfig.iteritems() if key in NAGIOS_OLD_CONF_KEYS)]}
return True, check_config, {}

try:
@@ -906,7 +906,7 @@ def load_check_directory(agentConfig, hostname):
# '/etc/dd-agent/checks.d/my_check.py' -> 'my_check'
check_name = config_path.rsplit('.', 1)[0].rsplit('/', 1)[-1]

conf_is_valid, check_config, invalid_check = _validate_config(config_path, check_name)
conf_is_valid, check_config, invalid_check = _validate_config(config_path, check_name, agentConfig)
init_failed_checks.update(invalid_check)
if not conf_is_valid:
continue
7 changes: 7 additions & 0 deletions tests/core/test_config.py
Original file line number Diff line number Diff line change
@@ -225,6 +225,13 @@ def testConfigInheritedCheck(self, *args):
self.assertEquals(1, len(checks['initialized_checks']))
self.assertEquals('valid_check_1', checks['initialized_checks'][0].check(None))

def testConfigDeprecatedNagiosConfig(self, *args):
copyfile('%s/valid_check_1.py' % FIXTURE_PATH,
'%s/nagios.py' % TEMP_ETC_CHECKS_DIR)
checks = load_check_directory({"nagios_perf_cfg": None, "additional_checksd": TEMP_ETC_CHECKS_DIR}, "foo")
self.assertEquals(1, len(checks['initialized_checks']))
self.assertEquals('valid_check_1', checks['initialized_checks'][0].check(None))

def tearDown(self):
for _dir in self.TEMP_DIRS:
rmtree(_dir)

0 comments on commit 59cc583

Please sign in to comment.