更新时间:2025-08-29 GMT+08:00
分享

获取集群所有防护项

功能介绍

获取集群所有防护项

调用方法

请参见如何调用API

URI

GET /v5/{project_id}/cluster-protect/protection-item

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产。获取方式请参见获取项目ID

约束限制:

不涉及

取值范围:

字符长度1-256位

默认取值:

不涉及

表2 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

参数解释:

企业项目ID,用于过滤不同企业项目下的资产。获取方式请参见获取企业项目ID

如需查询所有企业项目下的资产请传参“all_granted_eps”。

约束限制:

开通企业项目功能后才需要配置企业项目ID参数。

取值范围:

字符长度1-256位

默认取值:

0,表示默认企业项目(default)。

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token,包含了用户的身份、权限等信息,在调用API接口时,可通过Token进行身份认证。获取方式请参见获取用户Token

约束限制:

不涉及

取值范围:

字符长度1-32768位

默认取值:

不涉及

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

total_num

Integer

总数

vuls

Array of strings

漏洞信息

baselines

Array of ClusterBaselineResponseInfo objects

基线信息

malwares

Array of ClusterMalwareResponseInfo objects

恶意文件信息

images

Array of ClusterImageResponseInfo objects

镜像信息

clusters

Array of ClusterItemResponseInfo objects

集群信息

表5 ClusterBaselineResponseInfo

参数

参数类型

描述

baseline_desc

String

检查项描述

baseline_index

String

检查项ID

baseline_type

String

检查项类型

表6 ClusterMalwareResponseInfo

参数

参数类型

描述

malware_type

String

恶意文件类型

表7 ClusterImageResponseInfo

参数

参数类型

描述

image_name

String

镜像名称

image_version

String

镜像版本

id

String

ID

表8 ClusterItemResponseInfo

参数

参数类型

描述

cluster_id

String

集群id

cluster_name

String

集群名称

cluster_ns

Array of strings

集群命名空间

cluster_labels

Array of strings

集群标签

protect_status

String

集群防护状态 | - "0" unprotected - "1" plugin error - "2" protected with policy - "3" deploy policy failed - "4" protected without policy - "5" uninstall failed - "6" uninstall - "7" installing

请求示例

获取集群所有防护项

GET https://{endpoint}/v5/{project_id}/cluster-protect/protection-item?enterprise_project_id=all_granted_eps

响应示例

状态码:200

请求已成功

{
  "vuls" : [ "CVE-2002-2443", "CVE-2005-1849", "CVE-2009-5155", "CVE-2011-2895", "CVE-2011-5325", "CVE-2012-3425", "CVE-2012-5630" ],
  "baselines" : [ {
    "baseline_desc" : "规则:需限制/etc/ssh/sshd_config的访问权限",
    "baseline_index" : "1.1",
    "baseline_type" : "SSH"
  }, {
    "baseline_desc" : "规则:使用更加安全的Ciphers算法",
    "baseline_index" : "1.10",
    "baseline_type" : "SSH"
  } ],
  "malwares" : [ {
    "malware_type" : "malwares"
  } ],
  "images" : [ {
    "id" : "43170",
    "image_name" : "anp-agent",
    "image_version" : "0.0.2"
  }, {
    "id" : "17518",
    "image_name" : "webshell-ljx",
    "image_version" : "v1"
  } ],
  "clusters" : [ {
    "cluster_id" : "08e932a3-a7f0-4d60-ae45-09a629eb3be7",
    "cluster_name" : "test-617-rrrrrrrr",
    "protect_status" : "1"
  }, {
    "cluster_id" : "441e4d05-7f90-11ee-b311-0255ac1001b2",
    "cluster_name" : "ops-show-cluster-1110",
    "cluster_ns" : [ "default", "cgs-provider", "monitoring", "test-dasd", "hss", "ljx-test" ],
    "protect_status" : "0"
  }, {
    "cluster_id" : "ba732ee6-3067-11ef-8743-0255ac1001b4",
    "cluster_name" : "liuzhaoling-tarenwudong",
    "cluster_ns" : [ "default", "hss" ],
    "protect_status" : "0"
  }, {
    "cluster_id" : "a24b6cb6-3469-11ef-846b-0255ac100b03",
    "cluster_name" : "cce-lxl-0627-2",
    "protect_status" : "0"
  } ],
  "total_num" : 2817
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.hss.v5.region.HssRegion;
import com.huaweicloud.sdk.hss.v5.*;
import com.huaweicloud.sdk.hss.v5.model.*;


public class ListClusterProtectionItemSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        HssClient client = HssClient.newBuilder()
                .withCredential(auth)
                .withRegion(HssRegion.valueOf("<YOUR REGION>"))
                .build();
        ListClusterProtectionItemRequest request = new ListClusterProtectionItemRequest();
        try {
            ListClusterProtectionItemResponse response = client.listClusterProtectionItem(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkhss.v5.region.hss_region import HssRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkhss.v5 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = HssClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(HssRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListClusterProtectionItemRequest()
        response = client.list_cluster_protection_item(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    hss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := hss.NewHssClient(
        hss.HssClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListClusterProtectionItemRequest{}
	response, err := client.ListClusterProtectionItem(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求已成功

错误码

请参见错误码

相关文档