From 734408435d0cfb7a315ba7f4026289169182ac90 Mon Sep 17 00:00:00 2001 From: Kristian Rune Larsen Date: Thu, 18 May 2017 15:43:53 +0200 Subject: [PATCH 1/3] Added two environment variables for configuring datadog api key --- datadog_callback.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/datadog_callback.py b/datadog_callback.py index 94c1e87..59aa0ce 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -59,7 +59,8 @@ def _load_conf(self): else: print "Could not load configuration, invalid file: {}".format(file_path) - return conf_dict.get('api_key', ''), conf_dict.get('url', 'https://app.datadoghq.com') + return conf_dict.get('api_key', os.environ.get('DATADOG_API_KEY', '')), conf_dict.get('url', 'https://app.datadoghq.com') + # Send event to Datadog def _send_event(self, title, alert_type=None, text=None, tags=None, host=None, event_type=None, event_object=None): From f6da38d698b4a50005f0dc1ea599035bd7a2e395 Mon Sep 17 00:00:00 2001 From: Maxime Mouial Date: Wed, 27 Dec 2017 13:52:16 -0500 Subject: [PATCH 2/3] First check environment variable then configuration file --- datadog_callback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog_callback.py b/datadog_callback.py index 59aa0ce..027cc37 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -59,7 +59,7 @@ def _load_conf(self): else: print "Could not load configuration, invalid file: {}".format(file_path) - return conf_dict.get('api_key', os.environ.get('DATADOG_API_KEY', '')), conf_dict.get('url', 'https://app.datadoghq.com') + return os.environ.get('DATADOG_API_KEY', conf_dict.get('api_key', '')), conf_dict.get('url', 'https://app.datadoghq.com') # Send event to Datadog From fe49f2f73a9702be208ed823201dd66129073163 Mon Sep 17 00:00:00 2001 From: Maxime Mouial Date: Wed, 27 Dec 2017 13:52:39 -0500 Subject: [PATCH 3/3] Update README and CHANGELOG --- CHANGELOG.md | 1 + README.md | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 069a3c9..b6f39a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG # 2.2.0 / 2017-12-27 - [FEATURE] Set log level to warning for the datadog and request packages. See [#24][] (thanks to @n0ts) - [FEATURE] Allow users to set a custom location for the configuration file. +- [FEATURE] Added environment variables for configuring datadog api key. See [#22][] (thanks to @pyconsult) # 2.1.0 / 2017-12-26 - [FEATURE] Disable callback if required python packages aren't installed. See [#28][] (thanks to @dobber) diff --git a/README.md b/README.md index dd7c36f..d9cd45d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,16 @@ Once the required libraries (see above) have been installed on the server: 1. Copy `datadog_callback.py` to your playbook callback directory (by default `callback_plugins/` in your playbook's root directory). Create the directory if it doesn't exist. -2. Create a `datadog_callback.yml` file alongside `datadog_callback.py`, +2. You have 3 ways to set your API key. The callback will first use the + environment variable, then the configuration file, then hostvars/vault. + +##### Using environment variable + +Set the environment variable `DATADOG_API_KEY`. + +##### Using a yaml file + +Create a `datadog_callback.yml` file alongside `datadog_callback.py`, and set its contents with your [API key](https://app.datadoghq.com/account/settings#api), as following: @@ -37,6 +46,8 @@ For exemple: ANSIBLE_DATADOG_CALLBACK_CONF_FILE=/etc/datadog/callback_conf.yaml ansible-playbook ... ``` +##### Using ansible hostvars and vault + Alternatively you can use the hostvars of the host ansible is being run from (preferably in the vault file): ``` datadog_api_key: