查询云服务器列表
功能介绍
查询云服务器列表
调用方法
请参见如何调用API。
URI
GET /v5/{project_id}/host-management/hosts
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
enterprise_project_id |
否 |
String |
企业项目ID,查询所有企业项目时填写:all_granted_eps |
version |
否 |
String |
主机开通的版本,包含如下7种输入。
|
agent_status |
否 |
String |
Agent状态,包含如下6种。
|
detect_result |
否 |
String |
检测结果,包含如下4种。
|
host_name |
否 |
String |
服务器名称 |
host_id |
否 |
String |
服务器ID |
host_status |
否 |
String |
主机状态,包含如下4种。
|
os_type |
否 |
String |
操作系统类型,包含如下2种。
|
private_ip |
否 |
String |
服务器私有IP |
public_ip |
否 |
String |
服务器公网IP |
ip_addr |
否 |
String |
公网或私网IP |
protect_status |
否 |
String |
防护状态,包含如下2种。
|
group_id |
否 |
String |
服务器组ID |
group_name |
否 |
String |
服务器组名称 |
has_intrusion |
否 |
Boolean |
存在告警事件 |
policy_group_id |
否 |
String |
策略组ID |
policy_group_name |
否 |
String |
策略组名称 |
charging_mode |
否 |
String |
收费模式,包含如下2种。
|
refresh |
否 |
Boolean |
是否强制从ECS同步主机 |
above_version |
否 |
Boolean |
是否返回比当前版本高的所有版本 |
outside_host |
否 |
Boolean |
是否华为云主机 |
asset_value |
否 |
String |
资产重要性,包含如下4种
|
label |
否 |
String |
资产标签 |
server_group |
否 |
String |
资产服务器组 |
agent_upgradable |
否 |
Boolean |
agent是否可升级 |
limit |
否 |
Integer |
每页显示数量 |
offset |
否 |
Integer |
偏移量:指定返回记录的开始位置 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值) |
region |
否 |
String |
Region ID |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
total_num |
Integer |
总数 |
data_list |
Array of Host objects |
查询弹性云服务器状态列表 |
参数 |
参数类型 |
描述 |
---|---|---|
host_name |
String |
服务器名称 |
host_id |
String |
服务器ID |
agent_id |
String |
Agent ID |
private_ip |
String |
私有IP地址 |
public_ip |
String |
弹性公网IP地址 |
enterprise_project_id |
String |
企业项目ID |
enterprise_project_name |
String |
所属企业项目名称 |
host_status |
String |
服务器状态,包含如下4种。
|
agent_status |
String |
Agent状态,包含如下5种。
|
install_result_code |
String |
安装结果,包含如下12种。
|
version |
String |
主机开通的版本,包含如下7种输入。
|
protect_status |
String |
防护状态,包含如下2种。
|
os_image |
String |
系统镜像 |
os_type |
String |
操作系统类型,包含如下2种。
|
os_bit |
String |
操作系统位数 |
detect_result |
String |
云主机安全检测结果,包含如下4种。
|
expire_time |
Long |
试用版到期时间(-1表示非试用版配额,当值不为-1时为试用版本过期时间) |
charging_mode |
String |
收费模式,包含如下2种。
|
resource_id |
String |
主机安全配额ID(UUID) |
outside_host |
Boolean |
是否非华为云机器 |
group_id |
String |
服务器组ID |
group_name |
String |
服务器组名称 |
policy_group_id |
String |
策略组ID |
policy_group_name |
String |
策略组名称 |
asset |
Integer |
资产风险 |
vulnerability |
Integer |
漏洞风险总数,包含Linux软件漏洞、Windows系统漏洞、Web-CMS漏洞、应用漏洞 |
baseline |
Integer |
基线风险总数,包含配置风险、弱口令 |
intrusion |
Integer |
入侵风险总数 |
asset_value |
String |
资产重要性,包含如下4种
|
labels |
Array of strings |
标签列表 |
agent_create_time |
Long |
agent安装时间,采用时间戳,默认毫秒, |
agent_update_time |
Long |
agent状态修改时间,采用时间戳,默认毫秒, |
agent_version |
String |
agent版本 |
upgrade_status |
String |
升级状态,包含如下4种。
|
upgrade_result_code |
String |
升级失败原因,只有当 upgrade_status 为 upgrade_failed 时才显示,包含如下6种。
|
upgradable |
Boolean |
该服务器agent是否可升级 |
open_time |
Long |
开启防护时间,采用时间戳,默认毫秒, |
protect_interrupt |
Boolean |
防护是否中断 |
请求示例
查询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 |
云服务器列表 |
错误码
请参见错误码。