How to use the datadog.api.Monitor.get_all function in datadog

To help you get started, we’ve selected a few datadog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DataDog / datadogpy / tests / unit / api / test_api.py View on Github external
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()
github trueaccord / DogPush / dogpush / dogpush.py View on Github external
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
github ansible / ansible / lib / ansible / modules / monitoring / datadog / datadog_monitor.py View on Github external
# 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)
github ansible / ansible / lib / ansible / modules / monitoring / datadog / datadog_monitor.py View on Github external
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 {}
github ansible / ansible / lib / ansible / modules / extras / monitoring / datadog_monitor.py View on Github external
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 {}
github DataDog / documentation / content / en / api / monitors / code_snippets / api-monitor-show-all.py View on Github external
from datadog import initialize, api

options = {
    'api_key': '',
    'app_key': ''
}

initialize(**options)

# Get all monitor details
print(api.Monitor.get_all())