查询云服务器列表
功能介绍
查询云服务器列表
调用方法
请参见如何调用API。
URI
GET /v5/{project_id}/host-management/hosts
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
租户项目ID 最小长度:1 最大长度:256 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
enterprise_project_id |
否 |
String |
企业项目ID,查询所有企业项目时填写:all_granted_eps 缺省值:0 最小长度:1 最大长度:256 |
version |
否 |
String |
主机开通的版本,包含如下7种输入。
最小长度:1 最大长度:64 |
agent_status |
否 |
String |
Agent状态,包含如下6种。
最小长度:1 最大长度:20 |
detect_result |
否 |
String |
检测结果,包含如下4种。
最小长度:1 最大长度:32 |
host_name |
否 |
String |
服务器名称 |
host_id |
否 |
String |
服务器ID |
host_status |
否 |
String |
主机状态,包含如下4种。
最小长度:1 最大长度:32 |
os_type |
否 |
String |
操作系统类型,包含如下2种。
最小长度:0 最大长度:64 |
private_ip |
否 |
String |
服务器私有IP |
public_ip |
否 |
String |
服务器公网IP |
ip_addr |
否 |
String |
公网或私网IP |
protect_status |
否 |
String |
防护状态,包含如下2种。
最小长度:1 最大长度:32 |
group_id |
否 |
String |
服务器组ID |
group_name |
否 |
String |
服务器组名称 最小长度:1 最大长度:64 |
has_intrusion |
否 |
Boolean |
存在告警事件 |
policy_group_id |
否 |
String |
策略组ID 最小长度:0 最大长度:128 |
policy_group_name |
否 |
String |
策略组名称 最小长度:0 最大长度:256 |
charging_mode |
否 |
String |
收费模式,包含如下2种。
最小长度:1 最大长度:32 |
refresh |
否 |
Boolean |
是否强制从ECS同步主机 |
above_version |
否 |
Boolean |
是否返回比当前版本高的所有版本 |
outside_host |
否 |
Boolean |
是否华为云主机 |
asset_value |
否 |
String |
资产重要性,包含如下4种
最小长度:0 最大长度:128 |
label |
否 |
String |
资产标签 最小长度:1 最大长度:64 |
server_group |
否 |
String |
资产服务器组 最小长度:1 最大长度:64 |
agent_upgradable |
否 |
Boolean |
agent是否可升级 |
limit |
否 |
Integer |
每页显示个数,默认10 最小值:0 最大值:200 缺省值:10 |
offset |
否 |
Integer |
偏移量:指定返回记录的开始位置,必须为数字,取值范围为大于或等于0,默认0 最小值:0 最大值:2000000 缺省值:0 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值) 最小长度:1 最大长度:32768 |
region |
否 |
String |
Region ID 最小长度:0 最大长度:128 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
total_num |
Integer |
总数 最小值:0 最大值:2097152 |
data_list |
Array of Host objects |
查询弹性云服务器状态列表 数组长度:0 - 10241 |
参数 |
参数类型 |
描述 |
---|---|---|
host_name |
String |
服务器名称 最小长度:0 最大长度:128 |
host_id |
String |
服务器ID 最小长度:0 最大长度:128 |
agent_id |
String |
Agent ID 最小长度:0 最大长度:128 |
private_ip |
String |
私有IP地址 最小长度:0 最大长度:128 |
public_ip |
String |
弹性公网IP地址 最小长度:0 最大长度:128 |
enterprise_project_id |
String |
企业项目ID 最小长度:0 最大长度:256 |
enterprise_project_name |
String |
所属企业项目名称 最小长度:0 最大长度:256 |
host_status |
String |
服务器状态,包含如下4种。
最小长度:1 最大长度:32 |
agent_status |
String |
Agent状态,包含如下5种。
最小长度:1 最大长度:32 |
install_result_code |
String |
安装结果,包含如下12种。
最小长度:1 最大长度:32 |
version |
String |
主机开通的版本,包含如下7种输入。
最小长度:1 最大长度:32 |
protect_status |
String |
防护状态,包含如下2种。
最小长度:1 最大长度:32 |
os_image |
String |
系统镜像 最小长度:0 最大长度:128 |
os_type |
String |
操作系统类型,包含如下2种。
最小长度:0 最大长度:128 |
os_bit |
String |
操作系统位数 最小长度:0 最大长度:128 |
detect_result |
String |
云主机安全检测结果,包含如下4种。
最小长度:1 最大长度:32 |
expire_time |
Long |
试用版到期时间(-1表示非试用版配额,当值不为-1时为试用版本过期时间) 最小值:0 最大值:4824695185000 |
charging_mode |
String |
收费模式,包含如下2种。
最小长度:1 最大长度:32 |
resource_id |
String |
主机安全配额ID(UUID) 最小长度:0 最大长度:128 |
outside_host |
Boolean |
是否非华为云机器 |
group_id |
String |
服务器组ID 最小长度:1 最大长度:128 |
group_name |
String |
服务器组名称 最小长度:1 最大长度:128 |
policy_group_id |
String |
策略组ID 最小长度:1 最大长度:128 |
policy_group_name |
String |
策略组名称 最小长度:1 最大长度:128 |
asset |
Integer |
资产风险 最小值:0 最大值:2097152 |
vulnerability |
Integer |
漏洞风险总数,包含Linux软件漏洞、Windows系统漏洞、Web-CMS漏洞、应用漏洞 最小值:0 最大值:2097152 |
baseline |
Integer |
基线风险总数,包含配置风险、弱口令 最小值:0 最大值:2097152 |
intrusion |
Integer |
入侵风险总数 最小值:0 最大值:2097152 |
asset_value |
String |
资产重要性,包含如下4种
最小长度:0 最大长度:128 |
labels |
Array of strings |
标签列表 最小长度:0 最大长度:64 数组长度:0 - 100 |
agent_create_time |
Long |
agent安装时间,采用时间戳,默认毫秒, 最小值:0 最大值:4824695185000 |
agent_update_time |
Long |
agent状态修改时间,采用时间戳,默认毫秒, 最小值:0 最大值:4824695185000 |
agent_version |
String |
agent版本 最小长度:1 最大长度:32 |
upgrade_status |
String |
升级状态,包含如下4种。
最小长度:1 最大长度:32 |
upgrade_result_code |
String |
升级失败原因,只有当 upgrade_status 为 upgrade_failed 时才显示,包含如下6种。
最小长度:1 最大长度:32 |
upgradable |
Boolean |
该服务器agent是否可升级 |
open_time |
Long |
开启防护时间,采用时间戳,默认毫秒, 最小值:0 最大值:4824695185000 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); HssClient client = HssClient.newBuilder() .withCredential(auth) .withRegion(HssRegion.valueOf("<YOUR REGION>")) .build(); ListHostStatusRequest request = new ListHostStatusRequest(); request.withEnterpriseProjectId("<enterprise_project_id>"); request.withVersion("<version>"); request.withAgentStatus("<agent_status>"); request.withDetectResult("<detect_result>"); request.withHostName("<host_name>"); request.withHostId("<host_id>"); request.withHostStatus("<host_status>"); request.withOsType("<os_type>"); request.withPrivateIp("<private_ip>"); request.withPublicIp("<public_ip>"); request.withIpAddr("<ip_addr>"); request.withProtectStatus("<protect_status>"); request.withGroupId("<group_id>"); request.withGroupName("<group_name>"); request.withHasIntrusion(<has_intrusion>); request.withPolicyGroupId("<policy_group_id>"); request.withPolicyGroupName("<policy_group_name>"); request.withChargingMode("<charging_mode>"); request.withRefresh(<refresh>); request.withAboveVersion(<above_version>); request.withOutsideHost(<outside_host>); request.withAssetValue("<asset_value>"); request.withLabel("<label>"); request.withServerGroup("<server_group>"); request.withAgentUpgradable(<agent_upgradable>); request.withLimit(<limit>); request.withOffset(<offset>); 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# coding: utf-8 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 = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("CLOUD_SDK_SK") credentials = BasicCredentials(ak, sk) \ client = HssClient.new_builder() \ .with_credentials(credentials) \ .with_region(HssRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListHostStatusRequest() request.enterprise_project_id = "<enterprise_project_id>" request.version = "<version>" request.agent_status = "<agent_status>" request.detect_result = "<detect_result>" request.host_name = "<host_name>" request.host_id = "<host_id>" request.host_status = "<host_status>" request.os_type = "<os_type>" request.private_ip = "<private_ip>" request.public_ip = "<public_ip>" request.ip_addr = "<ip_addr>" request.protect_status = "<protect_status>" request.group_id = "<group_id>" request.group_name = "<group_name>" request.has_intrusion = <HasIntrusion> request.policy_group_id = "<policy_group_id>" request.policy_group_name = "<policy_group_name>" request.charging_mode = "<charging_mode>" request.refresh = <Refresh> request.above_version = <AboveVersion> request.outside_host = <OutsideHost> request.asset_value = "<asset_value>" request.label = "<label>" request.server_group = "<server_group>" request.agent_upgradable = <AgentUpgradable> request.limit = <limit> request.offset = <offset> 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := hss.NewHssClient( hss.HssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListHostStatusRequest{} enterpriseProjectIdRequest:= "<enterprise_project_id>" request.EnterpriseProjectId = &enterpriseProjectIdRequest versionRequest:= "<version>" request.Version = &versionRequest agentStatusRequest:= "<agent_status>" request.AgentStatus = &agentStatusRequest detectResultRequest:= "<detect_result>" request.DetectResult = &detectResultRequest hostNameRequest:= "<host_name>" request.HostName = &hostNameRequest hostIdRequest:= "<host_id>" request.HostId = &hostIdRequest hostStatusRequest:= "<host_status>" request.HostStatus = &hostStatusRequest osTypeRequest:= "<os_type>" request.OsType = &osTypeRequest privateIpRequest:= "<private_ip>" request.PrivateIp = &privateIpRequest publicIpRequest:= "<public_ip>" request.PublicIp = &publicIpRequest ipAddrRequest:= "<ip_addr>" request.IpAddr = &ipAddrRequest protectStatusRequest:= "<protect_status>" request.ProtectStatus = &protectStatusRequest groupIdRequest:= "<group_id>" request.GroupId = &groupIdRequest groupNameRequest:= "<group_name>" request.GroupName = &groupNameRequest hasIntrusionRequest:= <has_intrusion> request.HasIntrusion = &hasIntrusionRequest policyGroupIdRequest:= "<policy_group_id>" request.PolicyGroupId = &policyGroupIdRequest policyGroupNameRequest:= "<policy_group_name>" request.PolicyGroupName = &policyGroupNameRequest chargingModeRequest:= "<charging_mode>" request.ChargingMode = &chargingModeRequest refreshRequest:= <refresh> request.Refresh = &refreshRequest aboveVersionRequest:= <above_version> request.AboveVersion = &aboveVersionRequest outsideHostRequest:= <outside_host> request.OutsideHost = &outsideHostRequest assetValueRequest:= "<asset_value>" request.AssetValue = &assetValueRequest labelRequest:= "<label>" request.Label = &labelRequest serverGroupRequest:= "<server_group>" request.ServerGroup = &serverGroupRequest agentUpgradableRequest:= <agent_upgradable> request.AgentUpgradable = &agentUpgradableRequest limitRequest:= int32(<limit>) request.Limit = &limitRequest offsetRequest:= int32(<offset>) request.Offset = &offsetRequest response, err := client.ListHostStatus(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
云服务器列表 |
错误码
请参见错误码。