更新时间:2025-08-15 GMT+08:00

查询云服务器列表

功能介绍

查询云服务器列表

调用方法

请参见如何调用API

URI

GET /v5/{project_id}/host-management/hosts

表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)。

version

String

参数解释

主机开通的版本

约束限制:

不涉及

取值范围

包含如下7种输入。

  • hss.version.null :无。

  • hss.version.basic :基础版。

  • hss.version.advanced :专业版。

  • hss.version.enterprise :企业版。

  • hss.version.premium :旗舰版。

  • hss.version.wtp :网页防篡改版。

  • hss.version.container.enterprise:容器版。

默认取值:

不涉及

agent_status

String

参数解释:

Agent的状态

约束限制:

不涉及

取值范围:

Agent的状态分为两类:

  • installed:已安装。已安装状态包含以下四种情况:

    • online:在线。表示Agent已经成功安装并且与HSS云端防护中心保持连接。

    • offline:离线。表示虽然Agent已经安装,但当前与HSS云端防护中心的连接中断。

    • install_failed:安装失败。表示在尝试安装过程中遇到错误或问题,导致安装未能完成。

    • installing:安装中。表示当前正在进行Agent安装。

  • not_installed :未安装。表示服务器中尚未安装Agent。

如果您要筛选除在线以外所有状态的Agent,可设置not_online(仅作为查询条件)

默认取值:

不涉及

detect_result

String

参数解释:

检测结果

约束限制:

不涉及

取值范围:

包含如下4种。

  • undetected :未检测。

  • clean :无风险。

  • risk :有风险。

  • scanning :检测中。

默认取值:

不涉及

host_name

String

参数解释:

服务器名称

约束限制:

不涉及

取值范围:

字符长度1-256位

默认取值:

不涉及

host_id

String

参数解释:

服务器ID

约束限制:

不涉及

取值范围:

字符长度1-64位

默认取值:

不涉及

host_status

String

参数解释:

主机状态

约束限制:

不涉及

取值范围:

包含如下4种。

  • ACTIVE :正在运行。

  • SHUTOFF :关机。

  • BUILDING :创建中。

  • ERROR :故障。

默认取值:

不涉及

os_type

String

参数解释:

操作系统类型

约束限制:

不涉及

取值范围:

包含如下2种。

  • Linux :Linux。

  • Windows :Windows。

默认取值:

不涉及

private_ip

String

参数解释:

服务器私有IP

约束限制:

不涉及

取值范围:

字符长度1-128位

默认取值:

不涉及

public_ip

String

服务器公网IP

ip_addr

String

参数解释:

公网或私网IP

约束限制:

不涉及

取值范围:

字符长度1-128位

默认取值:

不涉及

protect_status

String

参数解释:

防护状态

约束限制:

不涉及

取值范围:

包含如下3种:

  • closed :关闭。

  • opened :开启。

  • protection_exception :防护异常。

默认取值:

不涉及

group_id

String

服务器组ID

group_name

String

参数解释:

服务器组名称

约束限制:

不涉及

取值范围:

字符长度1-64位

默认取值:

不涉及

vpc_id

String

参数解释:

VPC的ID

约束限制:

不涉及

取值范围:

字符长度1-128位

默认取值:

不涉及

has_intrusion

Boolean

参数解释:

存在告警事件

约束限制:

不涉及

取值范围:

true或者false

默认取值:

不涉及

has_vul

Boolean

参数解释:

存在漏洞风险

约束限制:

不涉及

取值范围:

true或者false

默认取值:

不涉及

has_baseline

Boolean

参数解释:

存在基线风险

约束限制:

不涉及

取值范围:

true或者false

默认取值:

不涉及

sort_key

String

参数解释:

排序字段

约束限制:

不涉及

取值范围:

只支持risk_num

默认取值:

不涉及

sort_dir

String

参数解释:

排序的顺序

约束限制:

不涉及

取值范围:

  • asc: 正序

  • desc: 倒序

默认取值:

不涉及

policy_group_id

String

参数解释:

策略组ID

约束限制:

不涉及

取值范围:

字符长度0-128位

默认取值:

不涉及

policy_group_name

String

参数解释:

策略组名称

约束限制:

不涉及

取值范围:

字符长度1-256位

默认取值:

不涉及

charging_mode

String

参数解释

收费模式

约束限制:

不涉及

取值范围:

  • packet_cycle :包年/包月。

  • on_demand :按需。

默认取值:

不涉及

refresh

Boolean

参数解释 :

是否强制从ECS同步主机

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

get_common_login_locations

Boolean

参数解释 :

是否获取主机常用登录地信息

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

above_version

Boolean

参数解释 :

是否返回比当前版本高的所有版本

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

outside_host

Boolean

参数解释 :

是否华为云主机

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

asset_value

String

参数解释 :

资产重要性

约束限制 :

不涉及

取值范围 :

包含如下4种

  • important :重要资产

  • common :一般资产

  • test :测试资产

默认取值 :

不涉及

label

String

参数解释 :

资产标签

约束限制 :

不涉及

取值范围 :

字符长度1-64位

默认取值 :

不涉及

server_group

String

参数解释 :

资产服务器组

约束限制 :

不涉及

取值范围 :

字符长度1-64位

默认取值 :

不涉及

agent_upgradable

Boolean

参数解释 :

agent是否可升级

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

install_mode

Boolean

参数解释 :

是否安装模式场景

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

binding_key

Boolean

参数解释 :

是否绑定DEW密钥

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

protect_interrupt

Boolean

参数解释 :

是否防护中断

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

incluster

Boolean

参数解释 :

是否集群内节点

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

protect_degradation

Boolean

参数解释 :

是否防护降级

约束限制 :

不涉及

取值范围 :

true或者false

默认取值 :

不涉及

cluster_id

String

参数解释:

集群ID

约束限制:

不涉及

取值范围:

字符长度1-64位

默认取值:

不涉及

offset

Integer

参数解释:

偏移量:指定返回记录的开始位置

约束限制:

不涉及

取值范围:

最小值0,最大值2000000

默认取值:

默认为0

limit

Integer

参数解释:

每页显示个数

约束限制:

不涉及

取值范围:

取值10-200

默认取值:

10

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

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

约束限制:

不涉及

取值范围:

字符长度1-32768位

默认取值:

不涉及

region

String

参数解释:

区域ID,用于查询目的区域内的资产。获取方式请参见获取区域ID

约束限制:

不涉及

取值范围:

字符长度1-128位

默认取值:

不涉及

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

total_num

Integer

参数解释:

总数

取值范围:

取值0-2097152

data_list

Array of Host objects

参数解释:

查询弹性云服务器状态列表

取值范围:

不涉及

表5 Host

参数

参数类型

描述

host_name

String

参数解释:

服务器名称

取值范围:

字符长度1-128位

host_id

String

参数解释:

服务器ID

取值范围:

字符长度1-128位

agent_id

String

参数解释:

Agent ID

取值范围:

字符长度1-128位

private_ip

String

参数解释:

私有IP地址

取值范围:

字符长度1-128位

public_ip

String

参数解释:

弹性公网IP地址

取值范围:

字符长度1-128位

enterprise_project_id

String

参数解释:

企业项目ID

取值范围:

字符长度0-256位

enterprise_project_name

String

参数解释:

所属企业项目名称

取值范围:

字符长度0-256位

os_name

String

参数解释:

系统名称

取值范围:

字符长度0-128位

os_version

String

参数解释:

系统版本

取值范围:

字符长度0-256位

kernel_version

String

参数解释:

内核版本

取值范围:

字符长度0-256位

host_status

String

参数解释:

服务器状态

取值范围:

包含如下4种。

  • ACTIVE :运行中。

  • SHUTOFF :关机。

  • BUILDING :创建中。

  • ERROR :故障。

agent_status

String

参数解释:

Agent状态

取值范围:

包含如下6种。

  • installed :已安装。

  • not_installed :未安装。

  • online :在线。

  • offline :离线。

  • install_failed :安装失败。

  • installing :安装中。

install_result_code

String

参数解释:

安装结果

取值范围:

包含如下12种。

  • install_succeed :安装成功。

  • network_access_timeout :网络不通,访问超时。

  • invalid_port :无效端口。

  • auth_failed :认证错误,口令不正确。

  • permission_denied :权限错误,被拒绝。

  • no_available_vpc :没有相同VPC的agent在线虚拟机。

  • install_exception :安装异常。

  • invalid_param :参数错误。

  • install_failed :安装失败。

  • package_unavailable :安装包失效。

  • os_type_not_support :系统类型错误。

  • os_arch_not_support :架构类型错误。

version

String

参数解释

主机开通的版本

取值范围

包含如下7种输入。

  • hss.version.null :无。

  • hss.version.basic :基础版。

  • hss.version.advanced :专业版。

  • hss.version.enterprise :企业版。

  • hss.version.premium :旗舰版。

  • hss.version.wtp :网页防篡改版。

  • hss.version.container.enterprise:容器版。

protect_status

String

参数解释

防护状态

取值范围

包含如下3种。

  • closed :未防护。

  • opened :防护中。

  • protection_exception :防护异常。

os_image

String

参数解释

系统镜像

取值范围

字符长度0-128位

os_type

String

参数解释

操作系统类型

取值范围

包含如下2种。

  • Linux :Linux。

  • Windows :Windows。

os_bit

String

参数解释

操作系统位数

取值范围

字符长度0-128位

detect_result

String

参数解释

云主机安全检测结果

取值范围

包含如下4种。

  • undetected :未检测。

  • clean :无风险。

  • risk :有风险。

  • scanning :检测中。

expire_time

Long

参数解释

试用版到期时间

取值范围

-1到4824695185000(-1表示非试用版配额,当值不为-1时为试用版本过期时间)

charging_mode

String

参数解释

收费模式

取值范围

包含如下2种。

  • packet_cycle :包年/包月。

  • on_demand :按需。

resource_id

String

参数解释

主机安全配额ID(UUID)

取值范围

字符长度0-128位

outside_host

Boolean

参数解释

是否非华为云机器

取值范围

true或者false

group_id

String

参数解释

服务器组ID

取值范围

字符长度0-128位

group_name

String

参数解释

服务器组名称

取值范围

字符长度0-128位

policy_group_id

String

参数解释

策略组ID

取值范围

字符长度0-128位

policy_group_name

String

参数解释

策略组名称

取值范围

字符长度0-128位

asset

Integer

参数解释

资产风险

取值范围

0-2097152

vulnerability

Integer

参数解释

漏洞风险总数,包含Linux软件漏洞、Windows系统漏洞、Web-CMS漏洞、应用漏洞

取值范围

0-2097152

baseline

Integer

参数解释

基线风险总数,包含配置风险、弱口令

取值范围

0-2097152

intrusion

Integer

参数解释

入侵风险总数

取值范围

0-2097152

asset_value

String

参数解释

资产重要性

取值范围

包含如下3种

  • important :重要资产

  • common :一般资产

  • test :测试资产

labels

Array of strings

参数解释

标签列表

取值范围

不涉及

agent_create_time

Long

参数解释

agent安装时间,采用时间戳,默认毫秒

取值范围

0-4824695185000

agent_update_time

Long

参数解释

agent状态修改时间,采用时间戳,默认毫秒

取值范围

0-4824695185000

agent_version

String

参数解释

agent版本

取值范围

字符长度0-32位

upgrade_status

String

参数解释

升级状态

取值范围

包含如下4种。

  • not_upgrade :未升级,也就是默认状态,客户还没有给这台机器下发过升级。

  • upgrading :正在升级中。

  • upgrade_failed :升级失败。

  • upgrade_succeed :升级成功。

upgrade_result_code

String

参数解释

升级失败原因,只有当upgrade_status为upgrade_failed时才显示

取值范围

包含如下6种。

  • package_unavailable :升级包解析失败,升级文件有错误。

  • network_access_timeout :下载升级包失败,网络异常。

  • agent_offline :agent离线。

  • hostguard_abnormal :agent工作进程异常。

  • insufficient_disk_space :磁盘空间不足。

  • failed_to_replace_file :替换文件失败。

upgradable

Boolean

参数解释

该服务器agent是否可升级

取值范围

true或者false

open_time

Long

参数解释

开启防护时间,采用时间戳,默认毫秒

取值范围

0-4824695185000

protect_interrupt

Boolean

参数解释

防护是否中断

取值范围

true或者false

protect_degradation

Boolean

参数解释

防护是否降级

取值范围

true或者false

host_sources

String

参数解释

服务器来源

取值范围

包含如下3种。

  • ecs :华为云ecs。

  • outside :非华为云机器。

  • workspace :华为云workspace。

interrupt_reason

String

参数解释

防护中断原因

取值范围

字符长度1-32位

degradation_reason

String

参数解释

防护降级原因

取值范围

字符长度1-32位

key_name

String

参数解释

使用的密钥对名称

取值范围

字符长度1-32位

auto_open_version

String

参数解释

cce购买主机

取值范围

字符长度1-32位

install_progress

Integer

参数解释

安装进度

取值范围

0-100

vpc_id

String

参数解释

vpc id

取值范围

字符长度0-128位

common_login_area_codes

Array of integers

参数解释

后台识别服务器常用登录地编号

取值范围

不涉及

cluster_name

String

参数解释

集群名称

取值范围

字符长度1-128位

cluster_id

String

参数解释

集群id

取值范围

字符长度1-128位

请求示例

查询agent状态为在线的所有企业项目下的10台linux主机。

GET https://{endpoint}/v5/{project_id}/host-management/hosts?limit=10&offset=0&agent_status=online&os_type=Linux&enterprise_project_id=all_granted_eps

响应示例

状态码:200

请求已成功

{
  "total_num" : 1,
  "data_list" : [ {
    "agent_id" : "2758d2a61598fd9144cfa6b201049e7c0af8c3f1280cd24e3ec95a2f0811a2a2",
    "agent_status" : "online",
    "asset" : 0,
    "asset_value" : "common",
    "baseline" : 0,
    "charging_mode" : "packet_cycle",
    "detect_result" : "risk",
    "enterprise_project_id" : "all_granted_eps",
    "enterprise_project_name" : "default",
    "group_id" : "7c659ea3-006f-4687-9f1c-6d975d955f37",
    "group_name" : "default",
    "host_id" : "caa958ad-a481-4d46-b51e-6861b8864515",
    "host_name" : "ecs-r00431580-ubuntu",
    "host_status" : "ACTIVE",
    "intrusion" : 0,
    "expire_time" : -1,
    "os_bit" : "64",
    "os_type" : "Linux",
    "outside_host" : false,
    "policy_group_id" : "2758d2a61598fd9144cfa6b201049e7c0af8c3f1280cd24e3ec95a2f0811a2a2",
    "policy_group_name" : "wtp_ecs-r00431580-ubuntu(default)",
    "private_ip" : "192.168.0.182",
    "protect_status" : "opened",
    "protect_interrupt" : false,
    "public_ip" : "100.85.123.9",
    "resource_id" : "60f08ea4-c74e-4a45-be1c-3c057e373af2",
    "version" : "hss.version.wtp",
    "vulnerability" : 97,
    "labels" : [ "" ],
    "agent_create_time" : 0,
    "agent_update_time" : 0,
    "open_time" : 0
  } ]
}

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 ListHostStatusSolution {

    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();
        ListHostStatusRequest request = new ListHostStatusRequest();
        try {
            ListHostStatusResponse response = client.listHostStatus(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 = ListHostStatusRequest()
        response = client.list_host_status(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.ListHostStatusRequest{}
	response, err := client.ListHostStatus(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

请求已成功

错误码

请参见错误码