Skip to content

Commit

Permalink
Enable ntp check by default
Browse files Browse the repository at this point in the history
Also:

* Add a better way to have checks enabled by default
* Fix #620
* Ensure that we cast exception as string (otherwise pickle can fail
when persisting the collector status)
  • Loading branch information
remh committed Mar 16, 2015
1 parent d51fc9f commit c7cb52d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def warning(self, warning_message):
""" Add a warning message that will be printed in the info page
:param warning_message: String. Warning message to be displayed
"""
self.warnings.append(warning_message)
self.warnings.append(str(warning_message))

def get_library_info(self):
if self.library_versions is not None:
Expand Down Expand Up @@ -556,7 +556,7 @@ def run(self):
self.log.exception("Check '%s' instance #%s failed" % (self.name, i))
instance_status = check_status.InstanceStatus(i,
check_status.STATUS_ERROR,
error=e,
error=str(e),
tb=traceback.format_exc()
)
instance_statuses.append(instance_status)
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 23 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
'nagios_perf_cfg'
]

DEFAULT_CHECKS = ("network", "ntp")

class PathNotFound(Exception):
pass

Expand Down Expand Up @@ -781,14 +783,34 @@ def load_check_directory(agentConfig, hostname):

# Let's see if there is a conf.d for this check
conf_path = os.path.join(confd_path, '%s.yaml' % check_name)

# Default checks are checks that are enabled by default
# They read their config from the "[CHECKNAME].yaml.default" file
if check_name in DEFAULT_CHECKS:
default_conf_path = os.path.join(confd_path, '%s.yaml.default' % check_name)
else:
default_conf_path = None

conf_exists = False

if os.path.exists(conf_path):
conf_exists = True

elif not conf_exists and default_conf_path is not None:
if not os.path.exists(default_conf_path):
log.error("Default configuration file {0} is missing".format(default_conf_path))
continue
conf_path = default_conf_path
conf_exists = True

if conf_exists:
f = open(conf_path)
try:
check_config = check_yaml(conf_path)
except Exception, e:
log.exception("Unable to parse yaml config in %s" % conf_path)
traceback_message = traceback.format_exc()
init_failed_checks[check_name] = {'error':e, 'traceback':traceback_message}
init_failed_checks[check_name] = {'error':str(e), 'traceback':traceback_message}
continue
else:
# Compatibility code for the Nagios checks if it's still configured
Expand Down
10 changes: 9 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os.path
import tempfile

from config import get_config
from config import get_config, load_check_directory, DEFAULT_CHECKS

from util import PidFile, is_valid_hostname, Platform, windows_friendly_colon_split

Expand Down Expand Up @@ -96,6 +96,14 @@ def testWindowsSplit(self):
# cleanup
Platform.is_win32 = staticmethod(func)

def testDefaultChecks(self):
checks = load_check_directory({"additional_checksd": "/etc/dd-agent/checks.d/"}, "foo")
init_checks_names = [c.name for c in checks['initialized_checks']]

for c in DEFAULT_CHECKS:
self.assertTrue(c in init_checks_names)


if __name__ == '__main__':
unittest.main()

0 comments on commit c7cb52d

Please sign in to comment.