Skip to content

Instantly share code, notes, and snippets.

@clutchski
Created December 11, 2012 21:58
Show Gist options
  • Save clutchski/4262622 to your computer and use it in GitHub Desktop.
Save clutchski/4262622 to your computer and use it in GitHub Desktop.
diff --git a/config.py b/config.py
index 870b72f..4298319 100644
--- a/config.py
+++ b/config.py
@@ -2,6 +2,7 @@ import ConfigParser
import os
import logging
import logging.config
+import imp
import platform
import string
import subprocess
@@ -443,6 +444,7 @@ def get_checksd_path(osname):
log.error("No checks.d folder at '%s'.\n" % checksd_path)
sys.exit(3)
+
def load_check_directory(agentConfig):
''' Return the checks from checks.d. Only checks that have a configuration
file in conf.d will be returned. '''
@@ -457,9 +459,6 @@ def load_check_directory(agentConfig):
confd_path = get_confd_path(osname)
check_glob = os.path.join(checks_path, '*.py')
- # Update the python path before the import
- sys.path.append(checks_path)
-
# For backwards-compatability with old style checks, we have to load every
# checks.d module and check for a corresponding config OR check if the old
# config will "activate" the check.
@@ -467,9 +466,13 @@ def load_check_directory(agentConfig):
# Once old-style checks aren't supported, we'll just read the configs and
# import the corresponding check module
for check in glob.glob(check_glob):
- check_name = os.path.basename(check).split('.')[0]
try:
- check_module = __import__(check_name)
+ check_name = os.path.basename(check).split('.')[0]
+ # HACK: people tend to write checks with the exact same name as the
+ # library they are checking e.g. redis, cassandra, zookeeper, etc.
+ # this small hack prevents this from happening.
+ imp_name = '__ddagent_checksd__' + check_name
+ check_module = imp.load_source(imp_name, check)
except:
log.exception('Unable to import check module %s.py from checks.d' % check_name)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment