Help Center/ Log Tank Service/ API Reference/ APIs/ Alarm List/ Querying the Active or Historical Alarm List
Updated on 2025-08-21 GMT+08:00

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

Table 1 Path Parameters

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

Table 2 Query Parameters

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

  • active_alert: active alarms, which have not been cleared after being triggered.

  • history_alert: historical alarms, which have been manually cleared. For details, see Checking Alarms.

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

  • Minimum value: 0

  • Maximum value: 1000

Default Value

1000: returns 1,000 alarms in sequence.

Request Parameters

Table 3 Request header 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

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

whether_custom_field

Yes

Boolean

Definition

Whether to specify a custom query time range.

Constraints

N/A

Range

  • true: The query uses a custom time range, with the specific start and end times defined by start_time and end_time.

  • false: The query uses a relative time range, with the duration defined by the time_range field and measured backward from the current time.

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:

  • -1.-1.60: indicates that the data of the latest 60 minutes is queried. This query is based on the server time regardless of the current client time.

  • 1650852000000.1650852300000.5: indicates the five minutes from 10:00:00 to 10:05:00 on April 25, 2022 GMT+08:00.

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

Table 5 Sort

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

  • asc

  • desc

Default Value

desc

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

events

Array of Events objects

Definition

Alarm details.

page_info

PageInfo object

Definition

Pagination information.

Table 7 Events

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

  • SQL

  • Keyword

Table 8 Annotations

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

  • firing: triggered

  • resolved: restored

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

  • true: enables the alarm restoration function.

  • false: disables the alarm restoration function.

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

  • sql: SQL alarm rule

  • keywords: keyword alarm rule

Table 9 results

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

Table 10 Metadata

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

  • Info

  • Minor

  • Major

  • Critical

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

  • sql: SQL alarm rule

  • keywords: keyword alarm rule

  • search_analysis: Search | Analysis alarm rule

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

  • sql: SQL alarm rule

  • keywords: keyword alarm rule

Table 11 PageInfo

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.