列出资源标签

更新时间:2025-02-17 06:41:15

调用ListTagResources接口列出资源标签。

前提条件

参数说明

请求参数

名称

类型

是否必填

描述

示例值

名称

类型

是否必填

描述

示例值

resourceType

String

资源的类型。支持如下5种:

  • project:项目。

  • logstore:日志库。

  • dashboard:仪表盘。

  • machinegroup:机器组。

  • logtailconfig:logtail配置。

project

resourceId

List<String>

资源ID列表。resourceId 与 tagList 应至少存在一个。列表中每个资源 ID,根据resourceType的枚举值进行传参。举例如下:

  • project:projectName

  • logstore:projectName#logstore

  • dashboard:projectName#dashboard

  • machinegroup:projectName#machinegroup

  • logtailconfig:projectName#logtailconfig

ali-test-project

tagList

Map<String, String>

精确查询时,用于过滤的标签键值对。resourceId与 tagList应至少配置一个。最多设置20个标签键值对。key表示查询时用于过滤标签的键,例如 key 为"test-key"时,只会返回绑定了标签键为"test-key"的资源。value表示查询时用于过滤标签的值,当值为 null时表示只根据key过滤。

{t1=k1}

返回参数

返回参数说明,请参见ListTagResources - 列出资源标签

示例代码

import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.TagResource;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.ListTagResourcesRequest;
import com.aliyun.openservices.log.response.ListTagResourcesResponse;

import java.util.*;


public class ListTagResourcesExample {
    // 本示例从环境变量中获取AccessKey ID和AccessKey Secret。
    static String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
    static String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");

    //日志服务的服务接入点。此处以杭州为例,其它地域请根据实际情况填写。
    static String host = "cn-hangzhou.log.aliyuncs.com";
    //初始化日志服务client
    static Client client = new Client(host, accessId, accessKey);

    private static final String RESOURCE_TYPE = "project";
    private static final String RESOURCE_ID = "ali-peoject-test1";


    public static void main(String[] args) throws LogException {
        ListTagResourcesResponse resources = client.listTagResources(new ListTagResourcesRequest(RESOURCE_TYPE,
                Arrays.asList(RESOURCE_ID), Collections.singletonMap("t1", "k1")));
        List<TagResource> tagResources = resources.getTagResources();
        for (TagResource tagResource : tagResources) {
            System.out.println("Resource ID: " + tagResource.getResourceId());
            System.out.println("Resource Type: " + tagResource.getResourceType());
            System.out.println("Tag Key: " + tagResource.getTagKey());
            System.out.println("Tag Value: " + tagResource.getTagValue());
        }
    }
}

相关文档

  • 本页导读 (1)
  • 前提条件
  • 参数说明
  • 请求参数
  • 返回参数
  • 示例代码
  • 相关文档