mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow Datadog monitors to be retrieved by id instead of name. (#3456)
This commit is contained in:
parent
5454c562e9
commit
320ae068ed
1 changed files with 17 additions and 4 deletions
|
@ -105,6 +105,11 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
version_added: "2.3"
|
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 = '''
|
EXAMPLES = '''
|
||||||
|
@ -172,7 +177,8 @@ def main():
|
||||||
thresholds=dict(required=False, type='dict', default=None),
|
thresholds=dict(required=False, type='dict', default=None),
|
||||||
tags=dict(required=False, type='list', default=None),
|
tags=dict(required=False, type='list', default=None),
|
||||||
locked=dict(required=False, default=False, type='bool'),
|
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,7 +209,14 @@ def _fix_template_vars(message):
|
||||||
|
|
||||||
|
|
||||||
def _get_monitor(module):
|
def _get_monitor(module):
|
||||||
for monitor in api.Monitor.get_all():
|
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']:
|
if monitor['name'] == module.params['name']:
|
||||||
return monitor
|
return monitor
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in a new issue