Get information about your infrastructure hosts in Datadog, and mute or unmute any notifications from your hosts. See the Infrastructure page for more information.
This endpoint allows searching for hosts by name, alias, or tag.
Hosts live within the past 3 hours are included by default.
Retention is 7 days.
Results are paginated with a max of 1000 results at a time.
This endpoint requires the hosts_read permission.
OAuth apps require the hosts_read authorization scope to access this endpoint.
Arguments
Query Strings
Name
Type
Description
filter
string
String to filter search results.
sort_field
string
Sort hosts by this field.
sort_dir
string
Direction of sort. Options include asc and desc.
start
integer
Specify the starting point for the host search results. For example, if you set count to 100 and the first 100 results have already been returned, you can set start to 101 to get the next 100 results.
count
integer
Number of hosts to return. Max 1000.
from
integer
Number of seconds since UNIX epoch from which you want to search your hosts.
include_muted_hosts_data
boolean
Include information on the muted status of hosts and when the mute expires.
include_hosts_metadata
boolean
Include additional metadata about the hosts (agent_version, machine, platform, processor, etc.).
"""
Get all hosts for your organization returns "OK" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v1.api.hosts_apiimportHostsApiconfiguration=Configuration()withApiClient(configuration)asapi_client:api_instance=HostsApi(api_client)response=api_instance.list_hosts(filter="env:ci",)print(response)
# Get all hosts for your organization returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V1::HostsAPI.newopts={filter:"env:ci",}papi_instance.list_hosts(opts)
// Get all hosts for your organization returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV1")funcmain(){ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV1.NewHostsApi(apiClient)resp,r,err:=api.ListHosts(ctx,*datadogV1.NewListHostsOptionalParameters().WithFilter("env:ci"))iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `HostsApi.ListHosts`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `HostsApi.ListHosts`:\n%s\n",responseContent)}
// Get all hosts for your organization returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v1.api.HostsApi;importcom.datadog.api.client.v1.api.HostsApi.ListHostsOptionalParameters;importcom.datadog.api.client.v1.model.HostListResponse;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();HostsApiapiInstance=newHostsApi(defaultClient);try{HostListResponseresult=apiInstance.listHosts(newListHostsOptionalParameters().filter("env:ci"));System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling HostsApi#listHosts");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Get all hosts for your organization returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV1::api_hosts::HostsAPI;usedatadog_api_client::datadogV1::api_hosts::ListHostsOptionalParams;#[tokio::main]asyncfnmain(){letconfiguration=datadog::Configuration::new();letapi=HostsAPI::with_config(configuration);letresp=api.list_hosts(ListHostsOptionalParams::default().filter("env:ci".to_string())).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Get all hosts for your organization returns "OK" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.HostsApi(configuration);constparams: v1.HostsApiListHostsRequest={filter:"env:ci",};apiInstance.listHosts(params).then((data: v1.HostListResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
This endpoint returns the total number of active and up hosts in your Datadog account.
Active means the host has reported in the past hour, and up means it has reported in the past two hours.
This endpoint requires the hosts_read permission.
OAuth apps require the hosts_read authorization scope to access this endpoint.
Arguments
Query Strings
Name
Type
Description
from
integer
Number of seconds from which you want to get total number of active hosts.
"""
Get the total number of active hosts returns "OK" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v1.api.hosts_apiimportHostsApiconfiguration=Configuration()withApiClient(configuration)asapi_client:api_instance=HostsApi(api_client)response=api_instance.get_host_totals()print(response)
# Get the total number of active hosts returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V1::HostsAPI.newpapi_instance.get_host_totals()
// Get the total number of active hosts returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV1")funcmain(){ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV1.NewHostsApi(apiClient)resp,r,err:=api.GetHostTotals(ctx,*datadogV1.NewGetHostTotalsOptionalParameters())iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `HostsApi.GetHostTotals`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `HostsApi.GetHostTotals`:\n%s\n",responseContent)}
// Get the total number of active hosts returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v1.api.HostsApi;importcom.datadog.api.client.v1.model.HostTotals;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();HostsApiapiInstance=newHostsApi(defaultClient);try{HostTotalsresult=apiInstance.getHostTotals();System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling HostsApi#getHostTotals");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Get the total number of active hosts returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV1::api_hosts::GetHostTotalsOptionalParams;usedatadog_api_client::datadogV1::api_hosts::HostsAPI;#[tokio::main]asyncfnmain(){letconfiguration=datadog::Configuration::new();letapi=HostsAPI::with_config(configuration);letresp=api.get_host_totals(GetHostTotalsOptionalParams::default()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Get the total number of active hosts returns "OK" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.HostsApi(configuration);apiInstance.getHostTotals().then((data: v1.HostTotals)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Mute a host returns "OK" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v1.api.hosts_apiimportHostsApifromdatadog_api_client.v1.model.host_mute_settingsimportHostMuteSettingsbody=HostMuteSettings(end=1579098130,message="Muting this host for a test!",override=False,)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=HostsApi(api_client)response=api_instance.mute_host(host_name="host_name",body=body)print(response)
# Mute a host returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V1::HostsAPI.newbody=DatadogAPIClient::V1::HostMuteSettings.new({_end:1579098130,message:"Muting this host for a test!",override:false,})papi_instance.mute_host("host_name",body)
// Mute a host returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV1")funcmain(){body:=datadogV1.HostMuteSettings{End:datadog.PtrInt64(1579098130),Message:datadog.PtrString("Muting this host for a test!"),Override:datadog.PtrBool(false),}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV1.NewHostsApi(apiClient)resp,r,err:=api.MuteHost(ctx,"host_name",body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `HostsApi.MuteHost`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `HostsApi.MuteHost`:\n%s\n",responseContent)}
// Mute a host returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v1.api.HostsApi;importcom.datadog.api.client.v1.model.HostMuteResponse;importcom.datadog.api.client.v1.model.HostMuteSettings;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();HostsApiapiInstance=newHostsApi(defaultClient);HostMuteSettingsbody=newHostMuteSettings().end(1579098130L).message("Muting this host for a test!").override(false);try{HostMuteResponseresult=apiInstance.muteHost("host_name",body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling HostsApi#muteHost");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Mute a host returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV1::api_hosts::HostsAPI;usedatadog_api_client::datadogV1::model::HostMuteSettings;#[tokio::main]asyncfnmain(){letbody=HostMuteSettings::new().end(1579098130).message("Muting this host for a test!".to_string()).override_(false);letconfiguration=datadog::Configuration::new();letapi=HostsAPI::with_config(configuration);letresp=api.mute_host("host_name".to_string(),body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Mute a host returns "OK" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.HostsApi(configuration);constparams: v1.HostsApiMuteHostRequest={body:{end: 1579098130,message:"Muting this host for a test!",override: false,},hostName:"host_name",};apiInstance.muteHost(params).then((data: v1.HostMuteResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Unmute a host returns "OK" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.HostsApi(configuration);constparams: v1.HostsApiUnmuteHostRequest={hostName:"host_name",};apiInstance.unmuteHost(params).then((data: v1.HostMuteResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));