タグ

タグ

タグエンドポイントを使用すると、ホストにタグを割り当てることができます。 例: role:database。これらのタグは、ホストから送信されるすべてのメトリクスに適用されます。タグを取得して特定のホストに適用するときは、名前でホストを参照します (yourhost.example.com)。

タグを担当するインフラストラクチャーのコンポーネントはソースによって識別されます。たとえば、有効なソースには、nagios、hudson、jenkins、users、feed、chef、puppet、git、bitbucket、fabric、capistrano などがあります。

タグの詳細は専用のドキュメントページをご覧ください。

POST https://api.datadoghq.eu/api/v1/tags/hosts/{host_name}https://api.ddog-gov.com/api/v1/tags/hosts/{host_name}https://api.datadoghq.com/api/v1/tags/hosts/{host_name}https://api.us3.datadoghq.com/api/v1/tags/hosts/{host_name}

概要

このエンドポイントを使用して、新しいタグをホストに追加できます。 オプションで、タグの由来を指定できます。

引数

パスパラメーター

名前

種類

説明

host_name [required]

string

This endpoint allows you to add new tags to a host, optionally specifying where the tags came from.

クエリ文字列

名前

種類

説明

source

string

リクエスト

Body Data (required)

ホストタグのリクエスト本文を更新します。

Expand All

フィールド

種類

説明

host

string

Your host name.

tags

[string]

A list of tags to apply to the host.

{
  "host": "test.host",
  "tags": [
    "environment:production"
  ]
}

応答

Created

Set of tags to associate with your host.

Expand All

フィールド

種類

説明

host

string

Your host name.

tags

[string]

A list of tags to apply to the host.

{
  "host": "test.host",
  "tags": [
    "environment:production"
  ]
}

Forbidden

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

コード例


# Path parameters
export host_name="CHANGE_ME"
# Curl command curl -X POST "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/tags/hosts/${host_name}" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF {} EOF
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    hostName := "hostName_example" // string | This endpoint allows you to add new tags to a host, optionally specifying where the tags came from.
    body := *datadog.NewHostTags() // HostTags | Update host tags request body.
    source := "chef" // string | The source of the tags. [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value). (optional)

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.TagsApi.CreateHostTags(ctx, hostName).Body(body).Source(source).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `TagsApi.CreateHostTags``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `CreateHostTags`: HostTags
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from TagsApi.CreateHostTags:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.TagsApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        TagsApi apiInstance = new TagsApi(defaultClient);
        String hostName = "hostName_example"; // String | This endpoint allows you to add new tags to a host, optionally specifying where the tags came from.
        HostTags body = new HostTags(); // HostTags | Update host tags request body.
        String source = "chef"; // String | The source of the tags. [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value).
        try {
	    HostTags result = apiInstance.createHostTags(hostName, body, new TagsApi.CreateHostTagsOptionalParameters()
                .source(source));
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling TagsApi#createHostTags");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import tags_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = tags_api.TagsApi(api_client)
    host_name = "host_name_example"  # str | This endpoint allows you to add new tags to a host, optionally specifying where the tags came from.
    body = HostTags(
        host="test.host",
        tags=[
            "environment:production",
        ],
    )  # HostTags | Update host tags request body.
    source = "chef"  # str | The source of the tags. [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value). (optional)

    # example passing only required values which don't have defaults set
    try:
        # Add tags to a host
        api_response = api_instance.create_host_tags(host_name, body)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->create_host_tags: %s\n" % e)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Add tags to a host
        api_response = api_instance.create_host_tags(host_name, body, source=source)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->create_host_tags: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::TagsAPI.new
host_name = 'host_name_example' # String | This endpoint allows you to add new tags to a host, optionally specifying where the tags came from.
body = DatadogAPIClient::V1::HostTags.new # HostTags | Update host tags request body.
opts = {
  source: 'chef' # String | The source of the tags. [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value).
}

begin
  # Add tags to a host
  result = api_instance.create_host_tags(host_name, body, opts)
  p result
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling TagsAPI->create_host_tags: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"

GET https://api.datadoghq.eu/api/v1/tags/hosts/{host_name}https://api.ddog-gov.com/api/v1/tags/hosts/{host_name}https://api.datadoghq.com/api/v1/tags/hosts/{host_name}https://api.us3.datadoghq.com/api/v1/tags/hosts/{host_name}

概要

特定のホストに適用されているタグのリストを返します。

引数

パスパラメーター

名前

種類

説明

host_name [required]

string

When specified, filters list of tags to those tags with the specified source.

クエリ文字列

名前

種類

説明

source

string

Source to filter.

応答

OK

Set of tags to associate with your host.

Expand All

フィールド

種類

説明

host

string

Your host name.

tags

[string]

A list of tags to apply to the host.

{
  "host": "test.host",
  "tags": [
    "environment:production"
  ]
}

Forbidden

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

コード例


# Path parameters
export host_name="CHANGE_ME"
# Curl command curl -X GET "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/tags/hosts/${host_name}" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    hostName := "hostName_example" // string | When specified, filters list of tags to those tags with the specified source.
    source := "source_example" // string | Source to filter. (optional)

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.TagsApi.GetHostTags(ctx, hostName).Source(source).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `TagsApi.GetHostTags``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `GetHostTags`: HostTags
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from TagsApi.GetHostTags:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.TagsApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        TagsApi apiInstance = new TagsApi(defaultClient);
        String hostName = "hostName_example"; // String | When specified, filters list of tags to those tags with the specified source.
        String source = "source_example"; // String | Source to filter.
        try {
	    HostTags result = apiInstance.getHostTags(hostName, new TagsApi.GetHostTagsOptionalParameters()
                .source(source));
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling TagsApi#getHostTags");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import tags_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = tags_api.TagsApi(api_client)
    host_name = "host_name_example"  # str | When specified, filters list of tags to those tags with the specified source.
    source = "source_example"  # str | Source to filter. (optional)

    # example passing only required values which don't have defaults set
    try:
        # Get host tags
        api_response = api_instance.get_host_tags(host_name)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->get_host_tags: %s\n" % e)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Get host tags
        api_response = api_instance.get_host_tags(host_name, source=source)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->get_host_tags: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::TagsAPI.new
host_name = 'host_name_example' # String | When specified, filters list of tags to those tags with the specified source.
opts = {
  source: 'source_example' # String | Source to filter.
}

begin
  # Get host tags
  result = api_instance.get_host_tags(host_name, opts)
  p result
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling TagsAPI->get_host_tags: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"

GET https://api.datadoghq.eu/api/v1/tags/hostshttps://api.ddog-gov.com/api/v1/tags/hostshttps://api.datadoghq.com/api/v1/tags/hostshttps://api.us3.datadoghq.com/api/v1/tags/hosts

概要

インフラストラクチャー全体のホストとタグのマッピングを返します。

引数

クエリ文字列

名前

種類

説明

source

string

When specified, filters host list to those tags with the specified source.

応答

OK

In this object, the key is the tag, the value is a list of host names that are reporting that tag.

Expand All

フィールド

種類

説明

tags

object

A list of tags to apply to the host.

<any-key>

[string]

A list of additional properties for tags.

{
  "tags": {
    "<any-key>": [
      "test.metric.host"
    ]
  }
}

Forbidden

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

コード例


# Curl command
curl -X GET "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/tags/hosts" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    source := "source_example" // string | When specified, filters host list to those tags with the specified source. (optional)

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.TagsApi.ListHostTags(ctx).Source(source).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `TagsApi.ListHostTags``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `ListHostTags`: TagToHosts
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from TagsApi.ListHostTags:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.TagsApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        TagsApi apiInstance = new TagsApi(defaultClient);
        String source = "source_example"; // String | When specified, filters host list to those tags with the specified source.
        try {
	    TagToHosts result = apiInstance.listHostTags(new TagsApi.ListHostTagsOptionalParameters()
                .source(source));
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling TagsApi#listHostTags");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import tags_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = tags_api.TagsApi(api_client)
    source = "source_example"  # str | When specified, filters host list to those tags with the specified source. (optional)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Get Tags
        api_response = api_instance.list_host_tags(source=source)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->list_host_tags: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::TagsAPI.new
opts = {
  source: 'source_example' # String | When specified, filters host list to those tags with the specified source.
}

begin
  # Get Tags
  result = api_instance.list_host_tags(opts)
  p result
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling TagsAPI->list_host_tags: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"

DELETE https://api.datadoghq.eu/api/v1/tags/hosts/{host_name}https://api.ddog-gov.com/api/v1/tags/hosts/{host_name}https://api.datadoghq.com/api/v1/tags/hosts/{host_name}https://api.us3.datadoghq.com/api/v1/tags/hosts/{host_name}

概要

このエンドポイントを使用して、1 つのホストにユーザーが割り当てた すべてのタグを削除できます。

引数

パスパラメーター

名前

種類

説明

host_name [required]

string

This endpoint allows you to remove all user-assigned tags for a single host.

クエリ文字列

名前

種類

説明

source

string

The source of the tags (e.g. chef, puppet). Complete list of source attribute values.

応答

OK

Forbidden

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

コード例


# Path parameters
export host_name="CHANGE_ME"
# Curl command curl -X DELETE "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/tags/hosts/${host_name}" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
package main

import (
    "context"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    hostName := "hostName_example" // string | This endpoint allows you to remove all user-assigned tags for a single host.
    source := "source_example" // string | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value). (optional)

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    r, err := apiClient.TagsApi.DeleteHostTags(ctx, hostName).Source(source).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `TagsApi.DeleteHostTags``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.TagsApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        TagsApi apiInstance = new TagsApi(defaultClient);
        String hostName = "hostName_example"; // String | This endpoint allows you to remove all user-assigned tags for a single host.
        String source = "source_example"; // String | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value).
        try {
	    apiInstance.deleteHostTags(hostName, new TagsApi.DeleteHostTagsOptionalParameters()
                .source(source));
        } catch (ApiException e) {
            System.err.println("Exception when calling TagsApi#deleteHostTags");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import tags_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = tags_api.TagsApi(api_client)
    host_name = "host_name_example"  # str | This endpoint allows you to remove all user-assigned tags for a single host.
    source = "source_example"  # str | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value). (optional)

    # example passing only required values which don't have defaults set
    try:
        # Remove host tags
        api_instance.delete_host_tags(host_name)
    except ApiException as e:
        print("Exception when calling TagsApi->delete_host_tags: %s\n" % e)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Remove host tags
        api_instance.delete_host_tags(host_name, source=source)
    except ApiException as e:
        print("Exception when calling TagsApi->delete_host_tags: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::TagsAPI.new
host_name = 'host_name_example' # String | This endpoint allows you to remove all user-assigned tags for a single host.
opts = {
  source: 'source_example' # String | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value).
}

begin
  # Remove host tags
  api_instance.delete_host_tags(host_name, opts)
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling TagsAPI->delete_host_tags: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"

PUT https://api.datadoghq.eu/api/v1/tags/hosts/{host_name}https://api.ddog-gov.com/api/v1/tags/hosts/{host_name}https://api.datadoghq.com/api/v1/tags/hosts/{host_name}https://api.us3.datadoghq.com/api/v1/tags/hosts/{host_name}

概要

このエンドポイントを使用して、インテグレーションソース内のすべてのタグを リクエストで提供されたタグで更新/置換できます。

引数

パスパラメーター

名前

種類

説明

host_name [required]

string

This endpoint allows you to update/replace all in an integration source with those supplied in the request.

クエリ文字列

名前

種類

説明

source

string

The source of the tags (e.g. chef, puppet). Complete list of source attribute values

リクエスト

Body Data (required)

ホストへのタグの追加

Expand All

フィールド

種類

説明

host

string

Your host name.

tags

[string]

A list of tags to apply to the host.

{
  "host": "test.host",
  "tags": [
    "environment:production"
  ]
}

応答

OK

Set of tags to associate with your host.

Expand All

フィールド

種類

説明

host

string

Your host name.

tags

[string]

A list of tags to apply to the host.

{
  "host": "test.host",
  "tags": [
    "environment:production"
  ]
}

Forbidden

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

Not Found

Error response object.

Expand All

フィールド

種類

説明

errors [required]

[string]

Array of errors returned by the API.

{
  "errors": [
    "Bad Request"
  ]
}

コード例


# Path parameters
export host_name="CHANGE_ME"
# Curl command curl -X PUT "https://api.datadoghq.eu"https://api.ddog-gov.com"https://api.datadoghq.com"https://api.us3.datadoghq.com/api/v1/tags/hosts/${host_name}" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${DD_API_KEY}" \ -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \ -d @- << EOF {} EOF
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "os"
    datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    hostName := "hostName_example" // string | This endpoint allows you to update/replace all in an integration source with those supplied in the request.
    body := *datadog.NewHostTags() // HostTags | Add tags to host
    source := "source_example" // string | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value) (optional)

    configuration := datadog.NewConfiguration()

    apiClient := datadog.NewAPIClient(configuration)
    resp, r, err := apiClient.TagsApi.UpdateHostTags(ctx, hostName).Body(body).Source(source).Execute()
    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `TagsApi.UpdateHostTags``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    }
    // response from `UpdateHostTags`: HostTags
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from TagsApi.UpdateHostTags:\n%s\n", responseContent)
}

Instructions

First install the library and its dependencies and then save the example to main.go and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
// Import classes:
import java.util.*;
import com.datadog.api.v1.client.ApiClient;
import com.datadog.api.v1.client.ApiException;
import com.datadog.api.v1.client.Configuration;
import com.datadog.api.v1.client.auth.*;
import com.datadog.api.v1.client.model.*;
import com.datadog.api.v1.client.api.TagsApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        TagsApi apiInstance = new TagsApi(defaultClient);
        String hostName = "hostName_example"; // String | This endpoint allows you to update/replace all in an integration source with those supplied in the request.
        HostTags body = new HostTags(); // HostTags | Add tags to host
        String source = "source_example"; // String | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value)
        try {
	    HostTags result = apiInstance.updateHostTags(hostName, body, new TagsApi.UpdateHostTagsOptionalParameters()
                .source(source));
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling TagsApi#updateHostTags");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Instructions

First install the library and its dependencies and then save the example to Example.java and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
import os
from dateutil.parser import parse as dateutil_parser
from datadog_api_client.v1 import ApiClient, ApiException, Configuration
from datadog_api_client.v1.api import tags_api
from datadog_api_client.v1.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
configuration = Configuration()

# Enter a context with an instance of the API client
with ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = tags_api.TagsApi(api_client)
    host_name = "host_name_example"  # str | This endpoint allows you to update/replace all in an integration source with those supplied in the request.
    body = HostTags(
        host="test.host",
        tags=[
            "environment:production",
        ],
    )  # HostTags | Add tags to host
    source = "source_example"  # str | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value) (optional)

    # example passing only required values which don't have defaults set
    try:
        # Update host tags
        api_response = api_instance.update_host_tags(host_name, body)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->update_host_tags: %s\n" % e)

    # example passing only required values which don't have defaults set
    # and optional values
    try:
        # Update host tags
        api_response = api_instance.update_host_tags(host_name, body, source=source)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling TagsApi->update_host_tags: %s\n" % e)

Instructions

First install the library and its dependencies and then save the example to example.py and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
require 'datadog_api_client'
api_instance = DatadogAPIClient::V1::TagsAPI.new
host_name = 'host_name_example' # String | This endpoint allows you to update/replace all in an integration source with those supplied in the request.
body = DatadogAPIClient::V1::HostTags.new # HostTags | Add tags to host
opts = {
  source: 'source_example' # String | The source of the tags (e.g. chef, puppet). [Complete list of source attribute values](https://docs.datadoghq.com/integrations/faq/list-of-api-source-attribute-value)
}

begin
  # Update host tags
  result = api_instance.update_host_tags(host_name, body, opts)
  p result
rescue DatadogAPIClient::V1::APIError => e
  puts "Error when calling TagsAPI->update_host_tags: #{e}"
end

Instructions

First install the library and its dependencies and then save the example to example.rb and run following commands:

              
export DD_SITE="datadoghq.comus3.datadoghq.comdatadoghq.euddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"