接口名

ListEventsRequest

阿里云2000元代金券免费领,最新优惠1折抢购,2核4G云服务器仅799元/3年,新老用户同享,立即抢购>>>

描述

返回阿里云某个产品在某个地域中的特定时间段内是否健康。

请求参数

名字 类型 含义
RegionId String 地域ID 如 cn-shenzhen
ProductId String 产品code 如 oss、ecs
EndDate String 查询时间截至点 如 2020-01-09
NumOfDay Integer 截至点往前几天 如 7

未region化的服务 regionId 设为 oo-region

产品code查询地域ID查询产品信息查询

返回参数

名字 类型 含义
code Integer 200代表成功,其余代表失败
data Array 该产品在该地域的事件列表
startTime Long 开始时间戳,单位毫秒
endTime Long 结束时间戳,单位毫秒(若未结束则空)
title String 状态标题
currentStateSeverity String 事件当前的严重状态:ALARM、NOTIFICATION、NORMAL

请求示例

Java

依赖

<dependencies>   <dependency>     <groupId>com.aliyun</groupId>     <artifactId>aliyun-java-sdk-core</artifactId>     <version>4.5.0</version>   </dependency>   <dependency>     <groupId>com.aliyun</groupId>     <artifactId>aliyun-java-sdk-status</artifactId>     <version>1.8</version>   </dependency> </dependencies>

代码

import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.status.model.v20200117.ListEventsRequest; import com.aliyuncs.status.model.v20200117.ListEventsResponse;  import java.util.List;  public class TestSdk {      public static void main (String[] args){         DefaultProfile profile = DefaultProfile.getProfile("","ak", "sk");         IAcsClient client = new DefaultAcsClient(profile);          ListEventsRequest request = new ListEventsRequest();         // 固定写好即可         request.setEndpoint("status.aliyuncs.com");         // 4个参数         request.setProductId("ecs");         request.setRegionId("cn-hangzhou");         request.setEndDate("2020-02-15");         request.setNumOfDay(6);                  try {             ListEventsResponse response = client.getAcsResponse(request);             Integer code = response.getCode();             System.out.println(code);             System.out.println(response.getRequestId());             if (200==code){                 List<ListEventsResponse.DataItem> dataItemList = response.getData();                 // 遍历每一条事件                 for (ListEventsResponse.DataItem dataItem : dataItemList) {                     System.out.println(dataItem.getTitle());                     System.out.println(dataItem.getCurrentStateSeverity());                     System.out.println(dataItem.getSartTime());                     System.out.println(dataItem.getEndTime());                 }             }         } catch (ClientException e) {             System.out.println("ErrCode:" + e.getErrCode());             System.out.println("ErrMsg:" + e.getErrMsg());             System.out.println("RequestId:" + e.getRequestId());         }     } }

Python

依赖

pip install aliyun-python-sdk-status

代码

from aliyunsdkcore.client import AcsClient from aliyunsdkstatus.request.v20200117 import ListEventsRequest import json  client = AcsClient("ak","sk","") request = ListEventsRequest.ListEventsRequest() # 固定写好即可 request.set_endpoint("status.aliyuncs.com")  # 4个参数 request.add_query_param("ProductId", "ons") request.add_query_param("EndDate", "2020-03-18") request.add_query_param("NumOfDay", 5) request.add_query_param("RegionId","cn-shenzhen")  response = client.do_action_with_exception(request) object = json.loads(response) print(object['Code']) print(object['RequestId']) if object['Total'] < 1:     print("no event") else:     dataList = object['Data']     for data in dataList:         print(data['Title'])         print(data['CurrentStateSeverity'])         print(data['SartTime'])         print(data['EndTime'])

返回示例

200 C58EBAC5-3685-4B68-B162-253B4B3028F8 测试 ALARM 1581317483000 null