How to use the datadog.api.Hosts.search 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 / Miscellany / update_host_tags_using_metadata_example.py View on Github external
def get_hosts(filter_string):
    host_count = api.Hosts.search(filter=initial_filter_string)['total_matching']
    print('%r hosts matching initial_filter_string' % host_count)
    num_req = host_count // 100 + 1
    print('%r number of api requests to query all matching hosts' % num_req)
    matching_hosts = []
    start_index = 0
    for i in range(1, num_req+1):
        print('api request %r of %r' % (i, num_req))
        host_list = api.Hosts.search(filter=initial_filter_string, sort_field='apps', count=100, start=start_index)['host_list']
        start_index += 100
        for host in host_list:
            matching_hosts.append(host)
    return matching_hosts
github DataDog / Miscellany / update_host_tags_using_metadata_example.py View on Github external
def get_hosts(filter_string):
    host_count = api.Hosts.search(filter=initial_filter_string)['total_matching']
    print('%r hosts matching initial_filter_string' % host_count)
    num_req = host_count // 100 + 1
    print('%r number of api requests to query all matching hosts' % num_req)
    matching_hosts = []
    start_index = 0
    for i in range(1, num_req+1):
        print('api request %r of %r' % (i, num_req))
        host_list = api.Hosts.search(filter=initial_filter_string, sort_field='apps', count=100, start=start_index)['host_list']
        start_index += 100
        for host in host_list:
            matching_hosts.append(host)
    return matching_hosts
github DataDog / documentation / content / api / hosts / code_snippets / api-host-mute.py View on Github external
from datadog import initialize, api

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

initialize(**options)

# Find a host to mute
hosts = api.Hosts.search(q='hosts:')
# Mute a host
api.Host.mute(hosts['results']['hosts'][0])
github DataDog / documentation / content / api / metrics / code_snippets / api-metrics-search.py View on Github external
from datadog import initialize, api

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

initialize(**options)

api.Hosts.search(q="metrics:system")
github DataDog / documentation / content / api / hosts / code_snippets / api-host-unmute.py View on Github external
from datadog import initialize, api

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

initialize(**options)

# Find a host to unmute
hosts = api.Hosts.search(q='hosts:')

# Unmute host
api.Host.unmute(hosts['results']['hosts'][0])
github insightfinder / InsightAgent / datadog / getmetrics_datadog.py View on Github external
def get_host_list():
    """Get available host list from Datadog API"""
    hosts_list = []
    host_totals = datadog.api.Hosts.totals()
    total_hosts = 0
    if 'total_active' in host_totals.keys():
        total_hosts = int(host_totals['total_active'])
    if total_hosts > 100:
        for index in range(0, total_hosts + 1, 100):
            result = datadog.api.Hosts.search(start=index)
            if 'host_list' in result.keys() and len(result['host_list']) != 0:
                for host_meta in result['host_list']:
                    hosts_list.append(host_meta["name"])
    else:
        result = datadog.api.Hosts.search()
        if 'host_list' in result.keys() and len(result['host_list']) != 0:
            for host_meta in result['host_list']:
                hosts_list.append(host_meta["name"])
    return hosts_list
github insightfinder / InsightAgent / datadog / getmetrics_datadog.py View on Github external
def get_host_list():
    """Get available host list from Datadog API"""
    hosts_list = []
    host_totals = datadog.api.Hosts.totals()
    total_hosts = 0
    if 'total_active' in host_totals.keys():
        total_hosts = int(host_totals['total_active'])
    if total_hosts > 100:
        for index in range(0, total_hosts + 1, 100):
            result = datadog.api.Hosts.search(start=index)
            if 'host_list' in result.keys() and len(result['host_list']) != 0:
                for host_meta in result['host_list']:
                    hosts_list.append(host_meta["name"])
    else:
        result = datadog.api.Hosts.search()
        if 'host_list' in result.keys() and len(result['host_list']) != 0:
            for host_meta in result['host_list']:
                hosts_list.append(host_meta["name"])
    return hosts_list