diff --git a/datadog_callback.py b/datadog_callback.py index c9694c0..4b912bc 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -1,15 +1,24 @@ import os.path import time -import datadog -import yaml +try: + import datadog + import yaml + HAS_MODULES = True +except ImportError: + HAS_MODULES = False +config_file = "datadog_callback.yml" class CallbackModule(object): def __init__(self): - # Read config and set up API client - api_key, url = self._load_conf(os.path.join(os.path.dirname(__file__), "datadog_callback.yml")) - datadog.initialize(api_key=api_key, api_host=url) + if not HAS_MODULES: + self.disabled = True + print 'Datadog callback disabled.\nMake sure you call all required libraries.' + + if not os.path.isfile(os.path.join(os.path.dirname(__file__),config_file)): + self.disabled = True + print 'Datadog callback disabled.\nMake sure you have "{0}" configuration file.'.format(config_file) self._playbook_name = None self._start_time = time.time() @@ -144,6 +153,10 @@ def runner_on_unreachable(self, host, res): ) def playbook_on_start(self): + # Read config and set up API client + api_key, url = self._load_conf(os.path.join(os.path.dirname(__file__), config_file)) + datadog.initialize(api_key=api_key, api_host=url) + # Retrieve the playbook name from its filename self._playbook_name, _ = os.path.splitext( os.path.basename(self.playbook.filename))