Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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])
from datadog import initialize, api
options = {
'api_key': '',
'app_key': ''
}
initialize(**options)
api.Hosts.search(q="metrics:system")
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])
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
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