diff options
author | Alex Paul <alex@alexpaul.net> | 2016-07-27 01:10:42 -0700 |
---|---|---|
committer | René Moser <mail@renemoser.net> | 2016-07-27 10:10:42 +0200 |
commit | 95dc240735795fb4234b7774a3a5ed2681c78d17 (patch) | |
tree | 177902acc18104d49ddc1448353a5b2129802611 /monitoring | |
parent | db979dde748cc3829cdcdee47f4526e06428fdde (diff) | |
download | ansible-modules-extras-95dc240735795fb4234b7774a3a5ed2681c78d17.tar.gz |
Add datadog_monitor param for datadog tags (#2541)
* Add datadog_monitor param for datadog tags
* Rename tags, add version_added
Diffstat (limited to 'monitoring')
-rw-r--r-- | monitoring/datadog_monitor.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/monitoring/datadog_monitor.py b/monitoring/datadog_monitor.py index 657c3b64..6a7a73b9 100644 --- a/monitoring/datadog_monitor.py +++ b/monitoring/datadog_monitor.py @@ -34,7 +34,7 @@ description: - "Manages monitors within Datadog" - "Options like described on http://docs.datadoghq.com/api/" version_added: "2.0" -author: "Sebastian Kornehl (@skornehl)" +author: "Sebastian Kornehl (@skornehl)" notes: [] requirements: [datadog] options: @@ -48,6 +48,11 @@ options: description: ["The designated state of the monitor."] required: true choices: ['present', 'absent', 'muted', 'unmuted'] + tags: + description: ["A list of tags to associate with your monitor when creating or updating. This can help you categorize and filter monitors."] + required: false + default: None + version_added: 2.2 type: description: - "The type of the monitor." @@ -153,6 +158,7 @@ def main(): escalation_message=dict(required=False, default=None), notify_audit=dict(required=False, default=False, type='bool'), thresholds=dict(required=False, type='dict', default=None), + tags=dict(required=False, type='list', default=None) ) ) @@ -189,9 +195,12 @@ 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=_fix_template_vars(module.params['message']), - options=options) + kwargs = dict(type=module.params['type'], query=module.params['query'], + name=module.params['name'], message=_fix_template_vars(module.params['message']), + options=options) + if module.params['tags'] is not None: + kwargs['tags'] = module.params['tags'] + msg = api.Monitor.create(**kwargs) if 'errors' in msg: module.fail_json(msg=str(msg['errors'])) else: @@ -206,9 +215,13 @@ 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=_fix_template_vars(module.params['message']), - options=options) + kwargs = dict(id=monitor['id'], query=module.params['query'], + name=module.params['name'], message=_fix_template_vars(module.params['message']), + options=options) + if module.params['tags'] is not None: + kwargs['tags'] = module.params['tags'] + msg = api.Monitor.update(**kwargs) + if 'errors' in msg: module.fail_json(msg=str(msg['errors'])) elif _equal_dicts(msg, monitor, ['creator', 'overall_state', 'modified']): |