diff options
author | Jordan Cohen <hypergig@gmail.com> | 2016-04-27 12:32:27 -0400 |
---|---|---|
committer | Jordan Cohen <hypergig@gmail.com> | 2016-04-27 12:32:27 -0400 |
commit | df055265d4aea09d47dc9200f5c3907503cca209 (patch) | |
tree | 42a9211b7cf9cfd1da7f67d03303afef7b0af0f8 /monitoring | |
parent | 95018b5fe89911924eec18265a9659fb5b03eea7 (diff) | |
download | ansible-modules-extras-df055265d4aea09d47dc9200f5c3907503cca209.tar.gz |
message template variable fix
Due to ansible/jinja2 templating, it is difficult to use the monitor message template variables as they need to be surrounded by `{{` and `}}`, this change addresses that issue by allowing the user to use `[[` and `]]` instead.
Diffstat (limited to 'monitoring')
-rw-r--r-- | monitoring/datadog_monitor.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/monitoring/datadog_monitor.py b/monitoring/datadog_monitor.py index c5aec1b5..34021d60 100644 --- a/monitoring/datadog_monitor.py +++ b/monitoring/datadog_monitor.py @@ -63,7 +63,7 @@ options: description: ["The name of the alert."] required: true message: - description: ["A message to include with notifications for this monitor. Email notifications can be sent to specific users by using the same '@username' notation as events."] + description: ["A message to include with notifications for this monitor. Email notifications can be sent to specific users by using the same '@username' notation as events. Monitor message template variables can be accessed by using double square brackets, i.e '[[' and ']]'."] required: false default: null silenced: @@ -176,6 +176,9 @@ def main(): elif module.params['state'] == 'unmute': unmute_monitor(module) +def _fix_template_vars(message): + return message.replace('[[', '{{').replace(']]', '}}') + def _get_monitor(module): for monitor in api.Monitor.get_all(): @@ -187,7 +190,7 @@ def _get_monitor(module): def _post_monitor(module, options): try: msg = api.Monitor.create(type=module.params['type'], query=module.params['query'], - name=module.params['name'], message=module.params['message'], + name=module.params['name'], message=_fix_template_vars(module.params['message']), options=options) if 'errors' in msg: module.fail_json(msg=str(msg['errors'])) @@ -204,7 +207,7 @@ def _equal_dicts(a, b, ignore_keys): def _update_monitor(module, monitor, options): try: msg = api.Monitor.update(id=monitor['id'], query=module.params['query'], - name=module.params['name'], message=module.params['message'], + name=module.params['name'], message=_fix_template_vars(module.params['message']), options=options) if 'errors' in msg: module.fail_json(msg=str(msg['errors'])) |