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 |
Parameter description: Project ID. For details about how to obtain it, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID. Constraints: N/A. Value range: N/A. Default value: N/A. |
domain_id |
Yes |
String |
Parameter description: Account ID. For details about how to obtain it, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID. Constraints: N/A. Value range: N/A. Default value: N/A. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
Yes |
String |
Parameter description: Type of alarms to be queried. active_alert: queries active alarms. history_alert: queries historical alarms. If this parameter is not transferred or is transferred with other values, information that meets the specified search criteria will be returned. Constraints: N/A. Value range: N/A. Default value: N/A. |
marker |
No |
String |
Parameter description: The value is the ID of the last record on the previous page (value of previous_marker or next_marker returned by the previous page). Constraints: N/A. Value range: N/A. Default value: N/A. |
limit |
No |
Integer |
Parameter description: Number of records on each page. Constraints: N/A. Value range: N/A. Default value: 1,000 |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Parameter description: User token obtained from IAM. For details about how to obtain it, see Obtaining a User Token. Constraints: N/A. Value range: N/A. Default value: N/A. |
Content-Type |
Yes |
String |
Parameter description: Set this parameter to application/json;charset=UTF-8. Constraints: N/A. Value range: N/A. Default value: N/A. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
whether_custom_field |
Yes |
Boolean |
Parameter description: Whether to specify a custom query time range. Constraints: N/A. Value range: N/A. Default value: false |
start_time |
No |
Long |
Parameter description: Start time of the custom time range (timestamp in milliseconds). Constraints: N/A. Value range: N/A. Default value: N/A. |
end_time |
No |
Long |
Parameter description: End time of the custom time range (timestamp in milliseconds). Constraints: N/A. Value range: N/A. Default value: N/A. |
time_range |
No |
String |
Parameter description: Alarms generated within this time range will be queried. This parameter addresses the issue of client and server time inconsistency. Constraints: In a single request, the following condition must be met: durationInMinutes x 60/period ≤ 1,440 Value range: N/A. Default value: N/A. |
search |
No |
String |
Parameter description: Field specified for fuzzy query, which can be left blank. If the value is not empty, fuzzy match will be performed. The metadata field is mandatory. Constraints: N/A. Value range: N/A. Default value: N/A. |
alarm_level_ids |
No |
Array of strings |
Parameter description: Alarm severity. The value can be Critical, Major, Minor, or Info. Constraints: You can only enter supported alarm severities. Value range: N/A. Default value: N/A. |
sort |
No |
Sort object |
Parameter description: Sorting order, which can be left blank. Constraints: N/A. Value range: N/A. Default value: N/A. |
step |
No |
Integer |
Parameter description: Statistical step, in milliseconds. Constraints: N/A. Value range: N/A. Default value: N/A. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
order_by |
Yes |
Array of strings |
Parameter description: List of sorted fields. Fields in this list are sorted based on the specified order. Constraints: N/A. Value range: N/A. Default value: N/A. |
order |
Yes |
String |
Parameter description: Sorting order. The value can be asc (ascending order) or desc (descending order). Constraints: N/A. Value range: N/A. Default value: desc |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
events |
Array of Events objects |
Parameter description: Event or alarm details. Value range: N/A. |
page_info |
PageInfo object |
Parameter description: Pagination information. Value range: N/A. |
Parameter |
Type |
Description |
---|---|---|
annotations |
Annotations object |
Parameter description: Alarm details. Value range: Minimum characters: 0 Maximum characters: 5,000 |
metadata |
Metadata object |
Parameter description: Alarm information. Value range: Minimum characters: 0 Maximum characters: 2,048 |
arrives_at |
Long |
Parameter description: Arrival time (timestamp in milliseconds). Value range: N/A. |
ends_at |
Long |
Parameter description: Alarm clearance time (timestamp in millisecond). Value range: N/A. |
id |
String |
Parameter description: Alarm ID. Value range: N/A. |
starts_at |
Long |
Parameter description: Alarm generation time (timestamp in millisecond). Value range: N/A. |
timeout |
Long |
Parameter description: Time when an alarm is automatically cleared (timestamp in millisecond). Value range: N/A. |
type |
String |
Parameter description: Alarm rule type (SQL/keyword). Value range: N/A. |
Parameter |
Type |
Description |
---|---|---|
message |
String |
Parameter description: Alarm list details. Value range: N/A. |
log_info |
String |
Parameter description: Log group/stream ID and name. Value range: N/A. |
current_value |
String |
Parameter description: Current value. Value range: N/A. |
old_annotations |
String |
Parameter description: Original data of SQL/keyword alarm details. Value range: N/A. Minimum: 0 |
alarm_action_rule_name |
String |
Parameter description: Alarm action rule. Value range: N/A. |
alarm_rule_alias |
String |
Parameter description: Alarm rule alias. Value range: N/A. |
alarm_rule_url |
String |
Parameter description: Alarm rule URL. Value range: N/A. |
alarm_status |
String |
Parameter description: Alarm triggering status. The value can be firing(triggered) or resolved (restored). Value range: N/A. |
condition_expression |
String |
Parameter description: Alarm triggering condition expression. Value range: N/A. |
condition_expression_with_value |
String |
Parameter description: Alarm triggering condition expression with values. Value range: N/A. |
notification_frequency |
String |
Parameter description: Notification frequency. Value range: N/A. |
recovery_policy |
Boolean |
Parameter description: Whether to enable the alarm restoration function. Value range: N/A. |
frequency |
String |
Parameter description: Statistical period. Value range: N/A. |
type |
String |
Parameter description: Alarm rule type. The value can be sql or keywords. Value range: N/A. |
Parameter |
Type |
Description |
---|---|---|
event_type |
String |
Parameter description: Alarm type. Value range: N/A. |
event_id |
String |
Parameter description: Alarm ID. Value range: N/A. |
event_severity |
String |
Parameter description: Alarm severity. The value can be Info, Minor, Major, or Critical. Value range: N/A. |
event_name |
String |
Parameter description: Alarm rule name. Value range: N/A. |
resource_type |
String |
Parameter description: Resource type. The value is Log Group/Stream. Value range: N/A. |
resource_id |
String |
Parameter description: Original log group/stream name. Value range: N/A. |
resource_provider |
String |
Parameter description: Alarm source. The value can be LTS. Value range: N/A. |
lts_alarm_type |
String |
Parameter description: Alarm rule type. The value can be *sql, keywords, or search_analysis (search and analysis). Value range: N/A. |
log_group_name |
String |
Parameter description: Original log group name. Value range: N/A. |
log_stream_name |
String |
Parameter description: Original log stream name. Value range: N/A. |
event_subtype |
String |
Parameter description: Alarm type. The value can be sql or keywords. Value range: N/A. |
Parameter |
Type |
Description |
---|---|---|
next_marker |
String |
Parameter description: Address of the next page. If an empty value is returned, there is no next page. Value range: N/A. |
previous_marker |
String |
Parameter description: Address of the previous page. Value range: N/A. |
current_count |
String |
Parameter description: Number of items returned on this page. Value 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.
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