diff options
author | Fabian Krämer <fabian.kraemer@gmail.com> | 2016-12-06 09:31:52 +1100 |
---|---|---|
committer | Adrian Likins <alikins@redhat.com> | 2016-12-05 17:31:52 -0500 |
commit | 461cabd176fccb78402b77567f3e885d48c596e0 (patch) | |
tree | e05d24bb82e77af601051098e3533f7f2c3d66b3 | |
parent | 409bce2fa19705578615df0c7559ee20f1412cc3 (diff) | |
download | ansible-modules-extras-461cabd176fccb78402b77567f3e885d48c596e0.tar.gz |
Allow Datadog monitors to be retrieved by id instead of name. (#3456)
-rw-r--r-- | monitoring/datadog_monitor.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/monitoring/datadog_monitor.py b/monitoring/datadog_monitor.py index 8fe9ded9..d10dd70c 100644 --- a/monitoring/datadog_monitor.py +++ b/monitoring/datadog_monitor.py @@ -105,6 +105,11 @@ options: required: false default: null version_added: "2.3" + id: + description: ["The id of the alert. If set, will be used instead of the name to locate the alert."] + required: false + default: null + version_added: "2.3" ''' EXAMPLES = ''' @@ -172,7 +177,8 @@ def main(): thresholds=dict(required=False, type='dict', default=None), tags=dict(required=False, type='list', default=None), locked=dict(required=False, default=False, type='bool'), - require_full_window=dict(required=False, default=None, type='bool') + require_full_window=dict(required=False, default=None, type='bool'), + id=dict(required=False) ) ) @@ -203,9 +209,16 @@ def _fix_template_vars(message): def _get_monitor(module): - for monitor in api.Monitor.get_all(): - if monitor['name'] == module.params['name']: - return monitor + if module.params['id'] is not None: + monitor = api.Monitor.get(module.params['id']) + if 'errors' in monitor: + module.fail_json(msg="Failed to retrieve monitor with id %s, errors are %s" % (module.params['id'], str(monitor['errors']))) + return monitor + else: + monitors = api.Monitor.get_all() + for monitor in monitors: + if monitor['name'] == module.params['name']: + return monitor return {} |