
# 查询事件类告警规则列表 - ListEvent2alarmRule
#### 功能介绍
查询事件类告警规则列表。（该接口为aom1.0界面接口，该接口即将下线，建议使用aom2.0接口[查询指标类或者事件类告警规则列表](https://support.huaweicloud.com/api-aom/ListMetricOrEventAlarmRule.html)接口。）
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-aom/aom_04_0057.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-aom/aom_04_0031.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                      | 访问级别 | 资源类型（\*为必须） | 条件键 | 别名 | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | aom:event2AlarmRule:list | List | -           | -   | -  | -      |
     
  
 
#### URI
GET /v2/{project_id}/event2alarm-rule
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                     |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，可以从控制台获取，也可以从调用API处获取。获取方式请参见：[获取项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html)。 |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                            |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 从IAM服务获取的用户Token。获取方式请参见：[获取Token](https://support.huaweicloud.com/api-aom/aom_04_0059.html)。 |
| Content-Type | 是    | String | 消息体的类型（格式）。指定类型为"application/json"。                                                           |
   
#### 响应参数
**状态码：200**
表3响应Body参数 
| 参数       | 参数类型                                                                                       | 描述       |
|:---|:---|:---|
| \[数组元素\] | Array of [Event2alarmRuleBody] objects | 事件类告警实体。 |
   
 表4Event2alarmRuleBody 
| 参数                | 参数类型                                                                                 | 描述                                                                       |
|:---|:---|:---|
| user_id           | String                                                                               | 用户项目id。                                                                  |
| name              | String                                                                               | 规则名称。规则名称包含大小写字母，数字，特殊字符（_-）和汉字组成，不能以特殊字符开头或结尾，最大长度为100。                 |
| description       | String                                                                               | 规则描述。描述包含大小写字母，数字，特殊字符（_-\<\>=,.）和汉字组成，不能以下划线、中划线开头结尾，最大长度为1024。         |
| create_time       | Long                                                                                 | 创建时间。仅支持UTC毫秒级时间戳。例如：2024-10-16 16:03:01需要通过工具转换成UTC毫秒级时间戳：1702759381000 |
| update_time       | Long                                                                                 | 更新时间。仅支持UTC毫秒级时间戳。例如：2024-10-16 16:03:01需要通过工具转换成UTC毫秒级时间戳：1702759381000 |
| resource_provider | String                                                                               | 事件源。                                                                     |
| metadata          | [metadata] object                           | 源数据。                                                                     |
| enable            | Boolean                                                                              | 规则是否启用。                                                                  |
| trigger_policies  | Array of [trigger_policies] objects | 触发策略。                                                                    |
| alarm_type        | String                                                                               | 告警类型。notification：直接告警。denoising：告警降噪。                                   |
| action_rule       | String                                                                               | 告警通知规则。                                                                  |
| inhibit_rule      | String                                                                               | 告警抑制规则。                                                                  |
| route_group_rule  | String                                                                               | 告警分组规则。                                                                  |
| event_names       | Array of strings                                                                     | 事件名称。                                                                    |
| migrated          | Boolean                                                                              | 是否迁移到2.0。                                                                |
| topics            | Array of [SmnTopics] objects               | smn信息。                                                                   |
   
 表5metadata 
| 参数          | 参数类型             | 描述       |
|:---|:---|:---|
| customField | Array of strings | 用户自定义标签。 |
   
 表6trigger_policies 
| 参数           | 参数类型    | 描述                                        |
|:---|:---|:---|
| id           | Integer | 自增编号。                                     |
| name         | String  | 事件名称。                                     |
| trigger_type | String  | 触发类型。accumulative: 累计触发，immediately: 立即触发 |
| period       | Integer | 触发周期。                                     |
| operator     | String  | 比较符。                                      |
| count        | Integer | 触发次数。                                     |
| level        | String  | 告警等级。                                     |
   
 表7SmnTopics 
| 参数           | 参数类型    | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| display_name | String  | Topic的显示名，推送邮件消息时，作为邮件发件人显示。显示名的长度为192byte或64个中文。默认值为空。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| name         | String  | 创建topic的名字。Topic名称只能包含大写字母、小写字母、数字、-和_，且必须由大写字母、小写字母或数字开头，长度为1到255个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| push_policy  | Integer | SMN消息推送策略。取值为0或1。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| status       | Integer | topic中订阅者的状态。 - 0：主题已删除或主题下订阅列表为空。   - 1：主题下的订阅列表存在状态为"已订阅"的订阅信息。   - 2：主题下的订阅信息状态处于"未订阅"或"已取消"。    |
| topic_urn    | String  | Topic的唯一的资源标识。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
   
**状态码：401**
表8响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                     |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
**状态码：403**
表9响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                     |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
**状态码：500**
表10响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                     |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
#### 请求示例
查询事件类告警规则列表
```
https://{endpoint}/v2/{project_id}/event2alarm-rule
```
#### 响应示例
**状态码：200**
OK 请求响应成功。
```
[ {
  "action_rule" : "1",
  "alarm_type" : "notification",
  "create_time" : 1701442632968,
  "description" : "",
  "enable" : true,
  "event_names" : [ ],
  "inhibit_rule" : "",
  "metadata" : {
    "customField" : [ "xxx" ]
  },
  "migrated" : false,
  "name" : "1jB5h6GnbY",
  "resource_provider" : "AOM",
  "route_group_rule" : "",
  "topics" : [ ],
  "trigger_policies" : [ {
    "count" : 99,
    "id" : 0,
    "level" : "",
    "name" : "",
    "operator" : ">=",
    "period" : 300,
    "trigger_type" : "accumulative"
  } ],
  "update_time" : 0,
  "user_id" : "2a473356cca5487f8373be891bffc1cf"
} ]
```
**状态码：401**
Unauthorized 在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。
```
{
  "error_code" : "SVCSTG.AMS.2000051",
  "error_msg" : "auth failed.",
  "error_type" : "AUTH_FAILED",
  "trace_id" : ""
}
```
**状态码：403**
Forbidden 请求被拒绝访问。返回该状态码，表明请求能够到达服务端，且服务端能够理解用户请求，但是拒绝做更多的事情，因为该请求被设置为拒绝访问，建议直接修改该请求，不要重试该请求。
```
{
  "error_code" : "AOM.0403",
  "error_msg" : "auth failed.",
  "error_type" : "AUTH_FAILED",
  "trace_id" : ""
}
```
**状态码：500**
InternalServerError 表明服务端能被请求访问到，但是不能理解用户的请求。
```
{
  "error_code" : "APM.00000500",
  "error_msg" : "Internal Server Error",
  "error_type" : "INTERNAL_SERVER_ERROR",
  "trace_id" : ""
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  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.aom.v2.region.AomRegion;
  import com.huaweicloud.sdk.aom.v2.*;
  import com.huaweicloud.sdk.aom.v2.model.*;
  public class ListEvent2alarmRuleSolution {
      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);
          AomClient client = AomClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                  .build();
          ListEvent2alarmRuleRequest request = new ListEvent2alarmRuleRequest();
          try {
              ListEvent2alarmRuleResponse response = client.listEvent2alarmRule(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());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkaom.v2.region.aom_region import AomRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkaom.v2 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 = AomClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(AomRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ListEvent2alarmRuleRequest()
          response = client.list_event2alarm_rule(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      aom "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/aom/v2/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, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := aom.AomClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := aom.NewAomClient(hcClient)
      request := &model.ListEvent2alarmRuleRequest{}
  response, err := client.ListEvent2alarmRule(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/AOM/sdk?api=ListEvent2alarmRule)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                                                                            |
|:---|:---|
| 200 | OK 请求响应成功。                                                                                    |
| 401 | Unauthorized 在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。                                     |
| 403 | Forbidden 请求被拒绝访问。返回该状态码，表明请求能够到达服务端，且服务端能够理解用户请求，但是拒绝做更多的事情，因为该请求被设置为拒绝访问，建议直接修改该请求，不要重试该请求。 |
| 500 | InternalServerError 表明服务端能被请求访问到，但是不能理解用户的请求。                                                 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-aom/ErrorCode.html)。
