查询活动或历史告警列表
功能介绍
查询活动或历史告警列表。您可以在请求参数中灵活设置筛选条件,例如:告警的时间范围、告警级别和告警来源等,系统接收到请求后,会利用高效的索引机制对告警数据库进行快速检索,精准筛选出符合条件的活动告警或历史告警记录。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,获取方式请参见:获取项目ID、获取账号ID、日志组ID、日志流ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
domain_id |
是 |
String |
参数解释: 账号ID,获取方式请参见:获取项目ID、获取账号ID、日志组ID、日志流ID。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
是 |
String |
参数解释: 查询告警类型。 active_alert:代表查询活动告警。 history_alert:代表查询历史告警。 不传或者传其他值,则返回指定查询条件的所有信息 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
marker |
否 |
String |
参数解释: 取值为上一页数据里最后一条记录的ID(填写上一页数据返回的previous_marker或者next_marker值)。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
limit |
否 |
Integer |
参数解释: 每页数据量。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 1000。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释: 从IAM服务获取的用户Token,获取方式请参见:获取用户Token。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
Content-Type |
是 |
String |
参数解释: 该字段填为:application/json;charset=UTF-8。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
whether_custom_field |
是 |
Boolean |
参数解释: 是否自定义查询时间段。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 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 |
参数解释: 统计步长(单位为毫秒)。 约束限制: 不涉及。 取值范围: 不涉及。 默认取值: 不涉及。 |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
events |
Array of Events objects |
参数解释: 事件或者告警详情。 取值范围: 不涉及。 |
page_info |
PageInfo object |
参数解释: 分页信息。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
annotations |
Annotations object |
参数解释: 告警详情。 取值范围: 最小长度:0 最大长度:5000 |
metadata |
Metadata object |
参数解释: 告警信息。 取值范围: 最小长度:0 最大长度:2048 |
arrives_at |
Long |
参数解释: 到达时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
ends_at |
Long |
参数解释: 告警清除时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
id |
String |
参数解释: 告警ID。 取值范围: 不涉及。 |
starts_at |
Long |
参数解释: 告警产生时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
timeout |
Long |
参数解释: 告警自动清除时间(单位为毫秒时间戳)。 取值范围: 不涉及。 |
type |
String |
参数解释: 告警规则类型(SQL/关键词)。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
message |
String |
参数解释: 告警列表详情。 取值范围: 不涉及。 |
log_info |
String |
参数解释: 日志组/流ID名称。 取值范围: 不涉及。 |
current_value |
String |
参数解释: 当前值。 取值范围: 不涉及。 |
old_annotations |
String |
参数解释: (SQL/关键词)告警详情原始数据。 取值范围: 不涉及。 最小长度:0 |
alarm_action_rule_name |
String |
参数解释: 告警行动规则。 取值范围: 不涉及。 |
alarm_rule_alias |
String |
参数解释: 告警规则别名。 取值范围: 不涉及。 |
alarm_rule_url |
String |
参数解释: 告警规则url。 取值范围: 不涉及。 |
alarm_status |
String |
参数解释: 告警触发状态。有触发(firing)和恢复(resolved)。 取值范围: 不涉及。 |
condition_expression |
String |
参数解释: 告警触发条件表达式。 取值范围: 不涉及。 |
condition_expression_with_value |
String |
参数解释: 告警触发表达式带值。 取值范围: 不涉及。 |
notification_frequency |
String |
参数解释: 通知频率。 取值范围: 不涉及。 |
recovery_policy |
Boolean |
参数解释: 是否开启告警恢复开关。 取值范围: 不涉及。 |
frequency |
String |
参数解释: 统计周期。 取值范围: 不涉及。 |
type |
String |
参数解释: 告警规则类型。有SQL(sql)/关键词告警(keywords)。 取值范围: 不涉及。 |
参数 |
参数类型 |
描述 |
---|---|---|
event_type |
String |
参数解释: 告警类型。 取值范围: 不涉及。 |
event_id |
String |
参数解释: 告警ID。 取值范围: 不涉及。 |
event_severity |
String |
参数解释: 告警级别。支持的告警级别分别有Info(提示)、Minor(次要)、Major(重要)、Critical(紧急)。 取值范围: 不涉及。 |
event_name |
String |
参数解释: 告警规则名称。 取值范围: 不涉及。 |
resource_type |
String |
参数解释: 资源类型。Log Group/Stream(日志组/流)。 取值范围: 不涉及。 |
resource_id |
String |
参数解释: 日志组/流原始名称。 取值范围: 不涉及。 |
resource_provider |
String |
参数解释: 告警源LTS。 取值范围: 不涉及。 |
lts_alarm_type |
String |
参数解释: 告警规则类型。支持的告警规则类型有SQL(sql)、关键词(keywords)、搜索分析(search_analysis)。 取值范围: 不涉及。 |
log_group_name |
String |
参数解释: 日志组原始名称。 取值范围: 不涉及。 |
log_stream_name |
String |
参数解释: 日志流原始名称。 取值范围: 不涉及。 |
event_subtype |
String |
参数解释: 告警类型。支持的告警类型有SQL告警(sql)和关键词告警(keywords)。 取值范围: 不涉及。 |
请求示例
查询活动或历史告警列表。
/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 |
请求响应成功。 |
错误码
请参见错误码。