Querying the Active or Historical Alarm List
Function
This API is used to query the active or historical alarm list. You can set filter criteria in the request parameters, such as the alarm time range, alarm severity, and alarm source. After receiving the request, the system uses the efficient index mechanism to quickly search the alarm database and accurately filter active or historical alarms that meet the criteria.
Calling Method
For details, see Calling APIs.
URI
POST /v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition Project ID. It can be obtained by calling an API or from the console. For details, see Obtaining a Project ID. Constraints N/A Range N/A Default Value N/A |
domain_id |
Yes |
String |
Definition Account ID. For details about how to obtain it, see Obtaining an Account ID. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
Yes |
String |
Definition Alarm type. The value can be active_alert or history_alert. If this parameter is not transferred or other values are transferred, all active and historical alarms that meet other query conditions are returned. Constraints N/A Range
Default Value N/A |
marker |
No |
String |
Definition Pagination marker. The subsequent value is the value of next_marker in the response body. Constraints N/A Range N/A Default Value 0: The pagination marker starts from 0, indicating that the alarm list is displayed in pages from 0. |
limit |
No |
Integer |
Definition Maximum number of alarms returned for each query. Constraints N/A Range
Default Value 1000: returns 1,000 alarms in sequence. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition User token obtained from IAM. For details about how to obtain it, see Obtaining a User Token. Constraints: N/A Range N/A Default Value N/A |
Content-Type |
Yes |
String |
Definition Message body format. Set this parameter to application/json;charset=utf8. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
whether_custom_field |
Yes |
Boolean |
Definition Whether to specify a custom query time range. Constraints N/A Range
Default Value false |
start_time |
No |
Long |
Definition Start time for querying alarms in a custom time range. The time range between start_time and end_time includes both the start time and end time. Constraints The values of start_time and end_time must be different. Range The value must be a timestamp, measured in milliseconds from January 1, 1970, 00:00:00 UTC. Default Value N/A |
end_time |
No |
Long |
Definition End time for querying alarms in a custom time range. The time range between start_time and end_time includes both the start time and end time. Constraints The values of start_time and end_time must be different. Range The value must be a timestamp, measured in milliseconds from January 1, 1970, 00:00:00 UTC. Default Value N/A |
time_range |
No |
String |
Definition Alarms generated within this time range will be queried. This parameter addresses the issue of client and server time inconsistency. Examples:
Constraints In a single request, the following condition must be met: durationInMinutes x 60/period ≤ 1,440 Range N/A Default Value N/A |
search |
No |
String |
Definition Field specified for fuzzy query, which can be left blank. If the value is not empty, fuzzy match will be performed. Constraints N/A Range Any field in metadata. Default Value N/A |
alarm_level_ids |
No |
Array of strings |
Definition Alarm severity. The supported alarm severities are Critical, Major, Minor, and Info. Constraints You can only enter supported alarm severities. |
sort |
No |
Sort object |
Definition Sorting order of the response result list. This parameter can be left blank. If it is left blank, alarms are sorted by the alarm generation time (starts_at) by default. Constraints N/A |
step |
No |
Long |
Definition Statistical step, in milliseconds. For example, to set the statistical step to one minute, enter 60000. Constraints N/A Range N/A Default Value N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
order_by |
Yes |
Array of strings |
Definition Field to sort the results by. For example, if you enter starts_at, the returned list will be sorted by alarm generation time. If the array length is 1, this parameter can only be set to starts_at. Constraints N/A |
order |
Yes |
String |
Definition Sorting order. Constraints N/A Range
Default Value desc |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
events |
Array of Events objects |
Definition Alarm details. |
page_info |
PageInfo object |
Definition Pagination information. |
Parameter |
Type |
Description |
---|---|---|
annotations |
Annotations object |
Definition Additional alarm field. |
metadata |
Metadata object |
Definition Alarm information. |
arrives_at |
Long |
Definition Alarm reporting time (timestamp in milliseconds). Range N/A |
ends_at |
Long |
Definition Alarm clearance time (timestamp in milliseconds). The value 0 indicates that the alarm is not deleted. Range N/A |
id |
String |
Definition Alarm ID. Range N/A |
starts_at |
Long |
Definition Alarm generation time (timestamp in millisecond). Range N/A |
timeout |
Long |
Definition Duration at which an alarm is automatically cleared, in millisecond. For example, to set the duration to one minute, enter 60,000. The default value is 7200 * 60000, which represents five days. This is calculated as: 5 days × 24 hours × 60 minutes × 60,000 ms. Range N/A |
type |
String |
Definition Alarm rule type. Range
|
Parameter |
Type |
Description |
---|---|---|
message |
String |
Definition Alarm triggering details. Range N/A |
log_info |
String |
Definition Log group/stream details. Range N/A |
current_value |
String |
Definition Current value of the condition expression. For example, if the condition expression is pv > 0, the value of current_value is {"pv":100}. Range N/A |
old_annotations |
String |
Definition Alarm rule details. Range N/A |
alarm_action_rule_name |
String |
Definition Alarm action rule name. Range N/A |
alarm_rule_alias |
String |
Definition Alarm rule alias. Range N/A |
alarm_rule_url |
String |
Definition Alarm rule URL. Range N/A |
alarm_status |
String |
Definition Alarm triggering status. Range
|
condition_expression |
String |
Definition Alarm triggering condition expression. Range N/A |
condition_expression_with_value |
String |
Definition Alarm triggering condition expression with values. For example, if the condition expression is pv > 0, the value of condition_expression_with_value is 100 > 0. Range N/A |
notification_frequency |
String |
Definition Notification frequency. Range N/A |
record_id |
String |
Definition Alarm ID. Range N/A |
recovery_policy |
Boolean |
Definition Whether to enable the alarm restoration function. Range
|
results |
Array of results objects |
Definition Alarm notification details. |
frequency |
String |
Definition Query frequency of alarms. Range N/A |
type |
String |
Definition Alarm rule type. Range
|
Parameter |
Type |
Description |
---|---|---|
eps_id |
String |
Definition Enterprise project ID. Range N/A |
log_group_name |
String |
Definition Log group name. Range N/A |
log_group_name_alias |
String |
Definition Log group alias. Range N/A |
log_stream_name |
String |
Definition Log stream name. Range N/A |
log_stream_name_alias |
String |
Definition Log stream alias. Range N/A |
time |
String |
Definition Alarm query frequency, for example, 1 hour. Range N/A |
Parameter |
Type |
Description |
---|---|---|
event_type |
String |
Definition Alarm type. Range alarm |
event_id |
String |
Definition Alarm rule ID. Range N/A |
event_severity |
String |
Definition Alarm severity. Range
|
event_name |
String |
Definition Alarm rule name. Range N/A |
resource_type |
String |
Definition Resource type. Range Log group/stream |
resource_id |
String |
Definition Original log group/stream name. Range N/A |
resource_provider |
String |
Definition Alarm source. Range LTS |
lts_alarm_type |
String |
Definition Alarm rule type. Range
|
log_group_name |
String |
Definition Original log group name. Range N/A |
log_stream_name |
String |
Definition Original log stream name. Range N/A |
event_subtype |
String |
Definition Alarm type. Range
|
Parameter |
Type |
Description |
---|---|---|
next_marker |
String |
Definition Address of the next page. If an empty value is returned, there is no next page. Range N/A |
previous_marker |
String |
Definition Address of the previous page. Range N/A |
current_count |
String |
Definition Total number of alarms on the current page. Range N/A |
Example Requests
Query the active or historical alarm list.
/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" } }
Example Responses
Status code: 200
The request is successful.
{ "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 Sample Code
The SDK sample code is as follows.
Query the active or historical alarm list.
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()); } } } |
Query the active or historical alarm list.
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) |
Query the active or historical alarm list.
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) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
200 |
The request is successful. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot