
# 获取告警发送结果 - ListNotifiedHistories
#### 功能介绍
该接口用于获取告警发送结果。
#### 调用方法
请参见[如何调用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:alarm:list | List | -           | -   | -  | -      |
     
  
 
#### URI
GET /v2/{project_id}/alarm-notified-histories
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                     |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，可以从控制台获取，也可以从调用API处获取。获取方式请参见：[获取项目ID](https://support.huaweicloud.com/api-aom/aom_04_0024.html)。 |
   
表2Query参数 
| 参数       | 是否必选 | 参数类型   | 描述     |
|:---|:---|:---|:---|
| event_sn | 是    | String | 告警流水号。 |
   
#### 请求参数
表3请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                            |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 从IAM服务获取的用户Token。获取方式请参见：[获取Token](https://support.huaweicloud.com/api-aom/aom_04_0059.html)。 |
| Content-Type | 是    | String | 消息体的类型（格式）。指定类型为"application/json"。                                                           |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数                 | 参数类型                                                                                                 | 描述      |
|:---|:---|:---|
| notified_histories | Array of [NotifiedHistoriesResult] objects | 通知历史列表。 |
   
 表5NotifiedHistoriesResult 
| 参数            | 参数类型                                                                             | 描述     |
|:---|:---|:---|
| event_sn      | String                                                                           | 告警流水号。 |
| notifications | Array of [Notifications] objects | 通知结果。  |
   
 表6Notifications 
| 参数               | 参数类型                                                               | 描述               |
|:---|:---|:---|
| action_rule      | String                                                             | 告警通知规则名称。        |
| notifier_channel | String                                                             | 通知类型。SMN：消息通知服务。 |
| smn_channel      | [SmnResponse] object | 通知结果详情。          |
   
 表7SmnResponse 
| 参数                   | 参数类型                                                                 | 描述                                                                       |
|:---|:---|:---|
| sent_time            | Long                                                                 | 发送时间。仅支持UTC毫秒级时间戳。例如：2024-10-16 16:03:01需要通过工具转换成UTC毫秒级时间戳：1702759381000 |
| smn_notified_history | Array of [SmnInfo] objects | 发送的通知的消息内容。                                                              |
| smn_request_id       | String                                                               | 请求smn服务的请求id。                                                            |
| smn_response_body    | String                                                               | 调用smn服务返回的信息。                                                            |
| smn_response_code    | String                                                               | 调用smn服务返回的http状态码。                                                       |
| smn_topic            | String                                                               | smn的主题。                                                                  |
   
 表8SmnInfo 
| 参数                      | 参数类型    | 描述          |
|:---|:---|:---|
| smn_notified_content    | String  | smn发送消息的内容。 |
| smn_subscription_status | Integer | smn的订阅的状态。  |
| smn_subscription_type   | String  | smn的订阅类型。   |
   
**状态码：401**
表9响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                           |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
**状态码：403**
表10响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                           |
|:---|:---|:---|
| error_code | String | **参数解释：** 非法请求错误码。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 错误信息。 **取值范围：** 不涉及。    |
| error_type | String | **参数解释：** 错误类型。 **取值范围：** 不涉及。    |
| trace_id   | String | **参数解释：** 请求id。 **取值范围：** 不涉及。    |
   
**状态码：500**
表11响应Body参数 
| 参数         | 参数类型   | 描述      |
|:---|:---|:---|
| error_code | String | 响应码。    |
| error_msg  | String | 响应信息描述。 |
| trace_id   | String | 响应id。   |
   
#### 请求示例
获取告警流水号为1044686593798963201的发送结果
```
https://{Endpoint}/v2/{project_id}/alarm-notified-histories?event_sn=1044686593798963201
```
#### 响应示例
**状态码：200**
OK 请求响应成功。
```
{
  "notified_histories" : [ {
    "event_sn" : "1044686593798963201",
    "notifications" : [ {
      "action_rule" : "lhy_alarm_action_test01",
      "notifier_channel" : "SMN",
      "smn_channel" : {
        "sent_time" : 1669114269797,
        "smn_notified_history" : [ {
          "smn_notified_content" : "<style>    span {        display: inline-block;        float: left;        font-size: 14px;    }    b {        display: inline-block;        float: left;        color: #252B3A;        font-size: 14px    }</style><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"       style=\"font-family:Helvetica,Arial,PingFangSC-Regular,Hiragino Sans GB;border-spacing:0px 14px;font-size:14px;padding-left: 30px;line-height:25px;\">    <thead>    <tr style=\"font-size:14px;\">        <td colspan=\"2\" style=\"line-height:28px;color:#6e6e6e;font-size:14px\">            <b>尊敬的&nbsp;</b>            <b>用户</b>            <b>&nbsp;，您好！</b>        </td>    </tr>    </thead>    <tr>        <td colspan=\"2\">            <span>您在&nbsp;</span>            <b>{region_name}</b>            <span>&nbsp;区域设置的告警行动规则</span>            <b>&nbsp;lhy_alarm_action_test01&nbsp;</b>            <span>新增</span>            <span>&nbsp;1&nbsp;条运维通知</span>                                    <span><span>，阈值规则为&nbsp;</span><b>lhy_test_001</b></span>            <span>。更多信息请登录AOM。</span>            <br>            <br>        </td>    </tr>    <tr style=\"font-size:14px;\">        <td colspan=\"2\">            <p style=\"margin-bottom: -20px; margin-top: -26px;\">                <span style=\"color:#252B3A;line-height:24px\">详细信息如下，请您查阅：</span>            </p>        </td>    </tr>    <td><div>账号：kaifatest;<br>通知类型：告警;<br>CAS应用名称: app-1;<br>告警类型：NA;<br>事件级别：紧急;<br>事件名称：lhy_test_001;<br>发生时间：2022-11-22 18:51:05 GMT+08:00;<br>事件源：AOM;<br>资源类型：Application;<br>资源标识：<br>&nbsp;&nbsp;casApplicationID:2d216a2b-9a58-452e-9a82-fc0c7cbcd322;<br>&nbsp;&nbsp;casApplicationName:app-1;<br>可能原因：当创建的阈值规则的指标数据达到阈值条件时且告警级别为“紧急”，产生此告警。;<br>详情：https://console.xxx/aom/alarmlist;<br>附加信息：阈值规则 lhy_test_001 状态从 “数据不足” 变为 “超限阈值” 。状态变化详细信息：指标名称为“cpuCoreLimit”，最新指标数据取值“0.250”，满足阈值条件“>=0”。;<br>修复建议：NA;<br><div/></td>  </table>",
          "smn_subscription_status" : 1,
          "smn_subscription_type" : "email"
        }, {
          "smn_notified_content" : "【AOM】发生紧急_告警_新增\n告警名称：lhy_test_001;\nCAS应用名称: app-1;\n发生时间：2022-11-22 18:51:05 GMT+08:00;\n详情：https://console.xxx/aom/alarmlist;\n告警内容：阈值规则 lhy_test_001 状态从 “数据不足” 变为 “超限阈值” 。状态变化详细信息：指标名称为“cpuCoreLimit”，最新指标数据取值“0.250”，满足阈值条件“>=0”。;\n本消息是由kaifatest在AOM告警规则中配置;更多信息请登录AOM。",
          "smn_subscription_status" : 0,
          "smn_subscription_type" : "sms"
        }, {
          "smn_notified_content" : "【AOM】发生紧急_告警_新增\n告警名称：lhy_test_001;\nCAS应用名称: app-1;\n发生时间：2022-11-22 18:51:05 GMT+08:00;\n详情：https://console.xxx/aom/alarmlist;\n告警内容：阈值规则 lhy_test_001 状态从 “数据不足” 变为 “超限阈值” 。状态变化详细信息：指标名称为“cpuCoreLimit”，最新指标数据取值“0.250”，满足阈值条件“>=0”。;\n本消息是由kaifatest在AOM告警规则中配置;更多信息请登录AOM。",
          "smn_subscription_status" : 0,
          "smn_subscription_type" : "sms"
        } ],
        "smn_request_id" : "600bfa7447da48068312bba0fb2b3afa",
        "smn_response_body" : "{\"message_id\":\"b5db3a3419b84cc29d438a7dba336c20\",\"request_id\":\"600bfa7447da48068312bba0fb2b3afa\"}",
        "smn_response_code" : "200",
        "smn_topic" : "lhy_test01"
      }
    } ]
  } ]
}
```
**状态码：401**
Unauthorized 在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。
```
{
  "error_code" : "AOM.0403",
  "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",
  "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 ListNotifiedHistoriesSolution {
      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();
          ListNotifiedHistoriesRequest request = new ListNotifiedHistoriesRequest();
          try {
              ListNotifiedHistoriesResponse response = client.listNotifiedHistories(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 = ListNotifiedHistoriesRequest()
          response = client.list_notified_histories(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.ListNotifiedHistoriesRequest{}
  response, err := client.ListNotifiedHistories(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=ListNotifiedHistories)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                                                                                            |
|:---|:---|
| 200 | OK 请求响应成功。                                                                                    |
| 401 | Unauthorized 在客户端提供认证信息后，返回该状态码，表明服务端指出客户端所提供的认证信息不正确或非法。                                     |
| 403 | Forbidden 请求被拒绝访问。返回该状态码，表明请求能够到达服务端，且服务端能够理解用户请求，但是拒绝做更多的事情，因为该请求被设置为拒绝访问，建议直接修改该请求，不要重试该请求。 |
| 500 | InternalServerError 表明服务端能被请求访问到，但是不能理解用户的请求。                                                 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-aom/ErrorCode.html)。
