From 974b9adc74ed33b58ed0a094853086d0ad567a3f Mon Sep 17 00:00:00 2001 From: Ivan Dimitrov Date: Mon, 26 Oct 2015 23:28:55 +0200 Subject: [PATCH 1/2] Checks existence of datadog_callback.yml before starting --- datadog_callback.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/datadog_callback.py b/datadog_callback.py index c9694c0..807cd1d 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -3,13 +3,13 @@ import datadog import yaml - +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 os.path.isfile(os.path.join(os.path.dirname(__file__),config_file)): + self.disabled = True + print 'Event sending to datadog disabled.\nMake sure you have "{0}" configuration file.'.format(config_file) self._playbook_name = None self._start_time = time.time() @@ -144,6 +144,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)) From 59f5d7a524da5cc5c81e54812db1b5c45d6e8278 Mon Sep 17 00:00:00 2001 From: Ivan Dimitrov Date: Mon, 26 Oct 2015 23:53:59 +0200 Subject: [PATCH 2/2] More descriptive error message --- datadog_callback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog_callback.py b/datadog_callback.py index 807cd1d..506e62a 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -9,7 +9,7 @@ class CallbackModule(object): def __init__(self): if not os.path.isfile(os.path.join(os.path.dirname(__file__),config_file)): self.disabled = True - print 'Event sending to datadog disabled.\nMake sure you have "{0}" configuration file.'.format(config_file) + print 'Datadog callback disabled.\nMake sure you have "{0}" configuration file.'.format(config_file) self._playbook_name = None self._start_time = time.time()