文档首页> 应用运维管理 AOM> API参考> API> 告警> 获取告警发送结果
更新时间:2024-06-20 GMT+08:00
分享

获取告警发送结果

功能介绍

获取告警发送结果。

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/alarm-notified-histories

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户从IAM申请到的projectid,一般为32位字符串。

最小长度:32

最大长度:32

表2 Query参数

参数

是否必选

参数类型

描述

event_sn

String

告警流水号

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token。

最小长度:1

最大长度:40960

Content-Type

String

指定类型为application/json。

枚举值:

  • application/json

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

notified_histories

Array of NotifiedHistoriesResult objects

通知历史列表。

表5 NotifiedHistoriesResult

参数

参数类型

描述

event_sn

String

告警流水号

最小长度:19

最大长度:19

notifications

Array of Notifications objects

通知结果

数组长度:0 - 100

表6 Notifications

参数

参数类型

描述

action_rule

String

告警行动规则名称

最小长度:1

最大长度:100

notifier_channel

String

通知类型。SMN:消息通知服务

枚举值:

  • SMN

smn_channel

SmnResponse object

通知结果详情

表7 SmnResponse

参数

参数类型

描述

sent_time

Long

发送时间。

最小值:0

最大值:9999999999

smn_notified_history

Array of SmnInfo objects

发送的通知的消息内容。

数组长度:1 - 100

smn_request_id

String

请求smn服务的请求id。

最小长度:32

最大长度:32

smn_response_body

String

调用smn服务返回的信息。

最小长度:0

最大长度:1024

smn_response_code

String

调用smn服务返回的http状态码。

最小长度:3

最大长度:3

smn_topic

String

smn的主题。

最小长度:1

最大长度:100

表8 SmnInfo

参数

参数类型

描述

smn_notified_content

String

smn发送消息的内容

最小长度:1

最大长度:9999999

smn_subscription_status

Long

smn的订阅的状态

最小长度:1

最大长度:1

smn_subscription_type

String

smn的订阅类型

最小长度:1

最大长度:100

状态码: 401

表9 响应Body参数

参数

参数类型

描述

error_code

String

错误码

最小长度:12

最大长度:12

error_msg

String

错误信息

最小长度:0

最大长度:1024

error_type

String

错误类型

最小长度:0

最大长度:128

trace_id

String

请求id

最小长度:32

最大长度:32

状态码: 403

表10 响应Body参数

参数

参数类型

描述

error_code

String

错误码

最小长度:12

最大长度:12

error_msg

String

错误信息

最小长度:0

最大长度:1024

error_type

String

错误类型

最小长度:0

最大长度:128

trace_id

String

请求id

最小长度:32

最大长度:32

状态码: 500

表11 响应Body参数

参数

参数类型

描述

error_code

String

响应码。

最小长度:13

最大长度:13

error_msg

String

响应信息描述。

最小长度:1

最大长度:100

trace_id

String

响应id。

最小长度:12

最大长度:12

请求示例

获取告警流水号为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,Microsoft YaHei,微软雅黑,Microsoft JhengHei;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" : null
}

状态码: 403

Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

{
  "error_code" : "AOM.0403",
  "error_msg" : "auth failed.",
  "error_type" : "AUTH_FAILED",
  "trace_id" : null
}

状态码: 500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

{
  "error_code" : "APM.00000500",
  "error_msg" : "Internal Server Error",
  "trace_id" : ""
}

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
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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        AomClient client = AomClient.newBuilder()
                .withCredential(auth)
                .withRegion(AomRegion.valueOf("<YOUR REGION>"))
                .build();
        ListNotifiedHistoriesRequest request = new ListNotifiedHistoriesRequest();
        request.withEventSn("<event_sn>");
        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());
        }
    }
}
 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 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"]

    credentials = BasicCredentials(ak, sk)

    client = AomClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(AomRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListNotifiedHistoriesRequest()
        request.event_sn = "<event_sn>"
        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)
 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"
    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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := aom.NewAomClient(
        aom.AomClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListNotifiedHistoriesRequest{}
	eventSnRequest:= "<event_sn>"
	request.EventSn = &eventSnRequest
	response, err := client.ListNotifiedHistories(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK 请求响应成功。

401

Unauthorized 在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。

403

Forbidden 请求被拒绝访问。返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。

500

InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。

错误码

请参见错误码

分享:

    相关文档

    相关产品