Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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: <your-api-key>
Expand Down
3 changes: 2 additions & 1 deletion datadog_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 os.environ.get('DATADOG_API_KEY', conf_dict.get('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):
Expand Down