L’endpoint tag vous permet d’assigner des tags à des hosts, par exemple : role:database. Ces tags sont appliqués à toutes les métriques envoyées par le host. Pour récupérer et appliquer des tags à un host spécifique, utilisez le nom du host en question (votrehost.exemple.com).
Le composant de votre infrastructure à l’origine d’un tag est identifié par une source. Les sources valides sont notamment nagios, hudson, jenkins, users, feed, chef, puppet, git, bitbucket, fabric, capistrano, etc.
/**
* Get Tags returns "OK" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.TagsApi(configuration);apiInstance.listHostTags().then((data: v1.TagToHosts)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Add tags to a host returns "Created" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v1.api.tags_apiimportTagsApifromdatadog_api_client.v1.model.host_tagsimportHostTagsbody=HostTags(host="test.host",tags=["environment:production",],)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=TagsApi(api_client)response=api_instance.create_host_tags(host_name="host_name",body=body)print(response)
# Add tags to a host returns "Created" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V1::TagsAPI.newbody=DatadogAPIClient::V1::HostTags.new({host:"test.host",tags:["environment:production",],})papi_instance.create_host_tags("host_name",body)
// Add tags to a host returns "Created" 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.HostTags{Host:datadog.PtrString("test.host"),Tags:[]string{"environment:production",},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV1.NewTagsApi(apiClient)resp,r,err:=api.CreateHostTags(ctx,"host_name",body,*datadogV1.NewCreateHostTagsOptionalParameters())iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `TagsApi.CreateHostTags`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `TagsApi.CreateHostTags`:\n%s\n",responseContent)}
/**
* Add tags to a host returns "Created" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.TagsApi(configuration);constparams: v1.TagsApiCreateHostTagsRequest={body:{host:"test.host",tags:["environment:production"],},hostName:"host_name",};apiInstance.createHostTags(params).then((data: v1.HostTags)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));