Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_return_raw_response(self):
# Test default initialization sets return_raw_response to False
initialize()
assert not api._return_raw_response
# Assert that we can set this to True
initialize(return_raw_response=True)
assert api._return_raw_response
# Assert we get multiple fields back when set to True
initialize(api_key="aaaaaaaaaa", app_key="123456", return_raw_response=True)
data, raw = api.Monitor.get_all()
def get_datadog_monitors():
monitors = datadog.api.Monitor.get_all(with_downtimes="true")
if CONFIG['dogpush']['ignore_prefix'] is not None:
monitors = [
m for m in monitors
if not m['name'].startswith(CONFIG['dogpush']['ignore_prefix'])
]
if not _check_monitor_names_unique(monitors):
raise DogPushException(
'Duplicate names found in remote datadog monitors.')
result = {}
for m in monitors:
m = _canonical_monitor(m)
result[m['name']] = m
return result
def _run(self):
return api.Monitor.get_all()
# Prepare Datadog
if not HAS_DATADOG:
module.fail_json(msg=missing_required_lib('datadogpy'), exception=DATADOG_IMP_ERR)
options = {
'api_key': module.params['api_key'],
'api_host': module.params['api_host'],
'app_key': module.params['app_key']
}
initialize(**options)
# Check if api_key and app_key is correct or not
# if not, then fail here.
response = api.Monitor.get_all()
if isinstance(response, dict):
msg = response.get('errors', None)
if msg:
module.fail_json(msg="Failed to connect Datadog server using given app_key and api_key : {0}".format(msg[0]))
if module.params['state'] == 'present':
install_monitor(module)
elif module.params['state'] == 'absent':
delete_monitor(module)
elif module.params['state'] == 'mute':
mute_monitor(module)
elif module.params['state'] == 'unmute':
unmute_monitor(module)
def _get_monitor(module):
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'] == _fix_template_vars(module.params['name']):
return monitor
return {}
def _get_monitor(module):
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 {}
from datadog import initialize, api
options = {
'api_key': '',
'app_key': ''
}
initialize(**options)
# Get all monitor details
print(api.Monitor.get_all())