查询活动或历史告警列表
功能介绍
查询活动或历史告警列表。您可以在请求参数中灵活设置筛选条件,例如:告警的时间范围、告警级别和告警来源等,系统接收到请求后,会利用高效的索引机制对告警数据库进行快速检索,精准筛选出符合条件的活动告警或历史告警记录。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,可以从调用API处获取,也可以从控制台获取。获取方式请参见:获取项目ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
domain_id |
是 |
String |
参数解释: 账号ID,获取方式请参见:获取账号ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: 查询告警类型。 约束限制: 不涉及。 取值范围:
默认取值: 不涉及。 |
marker |
否 |
String |
参数解释: 分页标记,后续值为返回体中的next_marker参数。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 0 |
limit |
否 |
Integer |
参数解释: 查询数量限制值。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 1000 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释: 从IAM服务获取的用户Token,获取方式请参见:获取用户Token。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
Content-Type |
是 |
String |
参数解释: 用于定义消息体的格式,该字段填为:application/json;charset=utf8。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
whether_custom_field |
是 |
Boolean |
参数解释: 是否自定义查询时间段。 约束限制: 不涉及。 取值范围: true:自定义查询时间段。 false:非自定义查询时间段。 默认取值: fasle |
start_time |
否 |
Long |
参数解释: 自定义时间段开始时间(单位为毫秒时间戳)。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
end_time |
否 |
Long |
参数解释: 自定义时间段结束时间(单位为毫秒时间戳)。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
time_range |
否 |
String |
参数解释: 查询某一段时间的告警,主要用于解决客户端时间和服务端时间不一致的情况。 例如:
约束限制: 单次请求中,查询时长与周期需要满足以下条件: durationInMinutes*60/period<=1440。 取值范围: 不涉及。 默认取值: 不涉及。 |
search |
否 |
String |
参数解释: 模糊查询匹配字段,可以为空。如果值不为空,可以模糊匹配。 约束限制: 不涉及。 取值范围: metadata任意字段。 默认取值: 不涉及。 |
alarm_level_ids |
否 |
Array of strings |
参数解释: 告警级别。支持的告警级别分别为Critical、Major、Minor、Info。 约束限制: 只能填写支持的告警级别。 |
sort |
否 |
Sort object |
参数解释: 返回列表的排序方式,可以为空。 约束限制: 不涉及。 |
step |
否 |
Integer |
参数解释: 统计步长(单位为毫秒),例如:一分钟则填写为60000。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
events |
Array of Events objects |
参数解释: 告警详情。 |
page_info |
PageInfo object |
参数解释: 分页信息。 |
参数 |
参数类型 |
描述 |
---|---|---|
annotations |
Annotations object |
参数解释: 告警附加字段。 |
metadata |
Metadata object |
参数解释: 告警信息。 |
arrives_at |
Long |
参数解释: 告警上报时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
ends_at |
Long |
参数解释: 告警清除时间(单位为毫秒时间戳),为0时表示未删除。 取值范围: 不涉及。 |
id |
String |
参数解释: 告警ID。 取值范围: 不涉及。 |
starts_at |
Long |
参数解释: 告警产生时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
timeout |
Long |
参数解释: 告警自动清除时间(单位为毫秒数),例如:一分钟则填写为60000。默认清除时间为5天,对应数字为7200 * 60000(即:5天 * 24小时 * 60分钟 * 60000毫秒)。 取值范围: 不涉及。 |
type |
String |
参数解释: 告警规则类型。 取值范围:
|
参数 |
参数类型 |
描述 |
---|---|---|
message |
String |
参数解释: 告警触发详情。 取值范围: 不涉及。 |
log_info |
String |
参数解释: 日志组/日志流详情。 取值范围: 不涉及。 |
current_value |
String |
参数解释: 条件表达式的当前值。例如:条件表达式为pv > 0,则current_value取值为:{"pv":100}。 取值范围: 不涉及。 |
old_annotations |
String |
参数解释: 告警规则详情。 取值范围: 不涉及。 |
alarm_action_rule_name |
String |
参数解释: 告警行动规则名称。 取值范围: 不涉及。 |
alarm_rule_alias |
String |
参数解释: 告警规则别名。 取值范围: 不涉及。 |
alarm_rule_url |
String |
参数解释: 告警规则url。 取值范围: 不涉及。 |
alarm_status |
String |
参数解释: 告警触发状态。 取值范围:
|
condition_expression |
String |
参数解释: 告警触发条件表达式。 取值范围: 不涉及。 |
condition_expression_with_value |
String |
参数解释: 告警触发表达式带值。例如:条件表达式为pv > 0,则condition_expression_with_value取值为:100 > 0。 取值范围: 不涉及。 |
notification_frequency |
String |
参数解释: 通知频率。 取值范围: 不涉及。 |
record_id |
String |
参数解释: 告警ID。 取值范围: 不涉及。 |
recovery_policy |
Boolean |
参数解释: 是否开启告警恢复开关。 取值范围:
|
results |
Array of results objects |
参数解释: 告警通知的详细信息。 |
frequency |
String |
参数解释: 告警统计周期。 取值范围: 不涉及。 |
type |
String |
参数解释: 告警规则类型。 取值范围:
|
参数 |
参数类型 |
描述 |
---|---|---|
eps_id |
String |
参数解释: 企业项目ID。 取值范围: 不涉及。 |
log_group_name |
String |
参数解释: 日志组名称。 取值范围: 不涉及。 |
log_group_name_alias |
String |
参数解释: 日志组别名。 取值范围: 不涉及。 |
log_stream_name |
String |
参数解释: 日志流名称。 取值范围: 不涉及。 |
log_stream_name_alias |
String |
参数解释: 日志流别名。 取值范围: 不涉及。 |
time |
String |
参数解释: 告警统计周期,例如:1小时。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
event_type |
String |
参数解释: 告警类型。 取值范围: alarm |
event_id |
String |
参数解释: 告警规则ID。 取值范围: 不涉及。 |
event_severity |
String |
参数解释: 告警级别。 取值范围:
|
event_name |
String |
参数解释: 告警规则名称。 取值范围: 不涉及。 |
resource_type |
String |
参数解释: 资源类型。 取值范围:
|
resource_id |
String |
参数解释: 日志组/日志流原始名称。 取值范围: 不涉及。 |
resource_provider |
String |
参数解释: 告警源。 取值范围: LTS |
lts_alarm_type |
String |
参数解释: 告警规则类型。 取值范围:
|
log_group_name |
String |
参数解释: 日志组原始名称。 取值范围: 不涉及。 |
log_stream_name |
String |
参数解释: 日志流原始名称。 取值范围: 不涉及。 |
event_subtype |
String |
参数解释: 告警类型。 取值范围:
|
请求示例
查询活动或历史告警列表。
/v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query?type=active_alert
POST https://{endpoint}/v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query?type={type}
{
"whether_custom_field" : false,
"start_time" : 0,
"end_time" : 0,
"time_range" : "30",
"search" : "",
"alarm_level_ids" : [ "Critical", "Major", "Minor", "Info" ],
"sort" : {
"order_by" : [ "starts_at" ],
"order" : "desc"
}
}
响应示例
状态码:200
请求响应成功。
{
"events" : [ {
"annotations" : {
"message" : "string",
"log_info" : "string",
"current_value" : "string"
},
"metadata" : {
"event_type" : "string",
"event_id" : "string",
"event_severity" : "string",
"event_name" : "string",
"resource_type" : "string",
"resource_id" : "string",
"resource_provider" : "string",
"lts_alarm_type" : "string"
},
"id" : "string",
"type" : "string"
} ],
"page_info" : {
"next_marker" : "string",
"previous_marker" : "string",
"current_count" : 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 |
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.lts.v2.region.LtsRegion;
import com.huaweicloud.sdk.lts.v2.*;
import com.huaweicloud.sdk.lts.v2.model.*;
public class ListActiveOrHistoryAlarmsSolution {
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);
LtsClient client = LtsClient.newBuilder()
.withCredential(auth)
.withRegion(LtsRegion.valueOf("<YOUR REGION>"))
.build();
ListActiveOrHistoryAlarmsRequest request = new ListActiveOrHistoryAlarmsRequest();
request.withDomainId("{domain_id}");
try {
ListActiveOrHistoryAlarmsResponse response = client.listActiveOrHistoryAlarms(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 huaweicloudsdklts.v2.region.lts_region import LtsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdklts.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 = LtsClient.new_builder() \
.with_credentials(credentials) \
.with_region(LtsRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListActiveOrHistoryAlarmsRequest()
request.domain_id = "{domain_id}"
response = client.list_active_or_history_alarms(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 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
lts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/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 := lts.NewLtsClient(
lts.LtsClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListActiveOrHistoryAlarmsRequest{}
request.DomainId = "{domain_id}"
response, err := client.ListActiveOrHistoryAlarms(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的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.lts.v2.region.LtsRegion;
import com.huaweicloud.sdk.lts.v2.*;
import com.huaweicloud.sdk.lts.v2.model.*;
public class ListActiveOrHistoryAlarmsSolution {
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);
LtsClient client = LtsClient.newBuilder()
.withCredential(auth)
.withRegion(LtsRegion.valueOf("<YOUR REGION>"))
.build();
ListActiveOrHistoryAlarmsRequest request = new ListActiveOrHistoryAlarmsRequest();
request.withDomainId("{domain_id}");
try {
ListActiveOrHistoryAlarmsResponse response = client.listActiveOrHistoryAlarms(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 huaweicloudsdklts.v2.region.lts_region import LtsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdklts.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 = LtsClient.new_builder() \
.with_credentials(credentials) \
.with_region(LtsRegion.value_of("<YOUR REGION>")) \
.build()
try:
request = ListActiveOrHistoryAlarmsRequest()
request.domain_id = "{domain_id}"
response = client.list_active_or_history_alarms(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 |
package main
import (
"fmt"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
lts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/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 := lts.NewLtsClient(
lts.LtsClientBuilder().
WithRegion(region.ValueOf("<YOUR REGION>")).
WithCredential(auth).
Build())
request := &model.ListActiveOrHistoryAlarmsRequest{}
request.DomainId = "{domain_id}"
response, err := client.ListActiveOrHistoryAlarms(request)
if err == nil {
fmt.Printf("%+v\n", response)
} else {
fmt.Println(err)
}
}
|
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求响应成功。 |
错误码
请参见错误码。