Updated on 2025-03-27 GMT+08:00

Querying the Active or Historical Alarm List

Function

This API is used to query the alarm list.

URI

POST /v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain a project ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID.

Minimum: 32

Maximum: 32

domain_id

Yes

String

Account ID. For details about how to obtain an account ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID.

Minimum: 32

Maximum: 32

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

type

Yes

String

Whether the alarm is an active alarm or a historical alarm.

marker

No

String

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).

Minimum: 0

Maximum: 1000

limit

No

Integer

Number of records on each page.

Minimum: 0

Maximum: 1000

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token obtained from IAM. For details about how to obtain a user token, see Obtaining a User Token.

Minimum: 1000

Maximum: 2000

Content-Type

Yes

String

Set this parameter to application/json;charset=UTF-8.

Minimum: 30

Maximum: 30

Table 4 Request body parameters

Parameter

Mandatory

Type

Description

whether_custom_field

Yes

Boolean

Whether to customize the query time segment.

start_time

No

Long

Start time of a customized time segment (timestamp).

Minimum: 13

Maximum: 13

end_time

No

Long

End time of a customized time segment (timestamp).

Minimum: 13

Maximum: 13

time_range

No

String

Time range specified to query data of the last N minutes when the client time is inconsistent with the server time. It can also be used to accurately query the data of a specified period.

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 5 minutes from 10:00:00 to 10:05:00 on April 25, 2022 UTC+08:00.

    Format: startTimeInMillis.endTimeInMillis.durationInMinutes

    Parameter description:

  • startTimeInMillis: start time (UTC) of the query, in milliseconds. If this parameter is set to -1, the server calculates the start time as follows: endTimeInMillis – durationInMinutes x 60 x 1,000. For example, -1.1650852300000.5 is equivalent to 1650852000000.1650852300000.5.

  • endTimeInMillis: end time (UTC) of the query, in milliseconds. If this parameter is set to -1, the server calculates the end time as follows: startTimeInMillis + durationInMinutes x 60 x 1,000. If the calculated end time is later than the current system time, the current system time is used. For example, 1650852000000.-1.5 is equivalent to 1650852000000.1650852300000.5.

  • durationInMinutes: time span, in minutes. The value must be greater than 0, and also greater than or equal to the result of "(endTimeInMillis – startTimeInMillis)/(60 x 1,000) – 1". If both the start time and end time are set to -1, the system sets the end time to the current UTC time (in milliseconds) and calculates the start time as follows: endTimeInMillis – durationInMinutes x 60 x 1,000. For example, -1.-1.60 indicates the latest 60 minutes.

    Constraint: In a single request, the following condition must be met: durationInMinutes x 60/period ≤ 1,440

Minimum: 1

Maximum: 32

search

No

String

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.

Minimum: 1

Maximum: 1024

alarm_level_ids

No

Array of strings

Alarm severity (Critical, Major, Minor, Info).

NOTE:

alarmLevelIds is a parameter of an earlier version and is currently compatible with this parameter. You are advised to use this parameter.

alarm_level_ids

sort

No

Sort object

Sorting order, which can be left blank.

step

No

Integer

Statistical step. Unit: ms. For example, if the duration is 1 minute, set this parameter to 60000.

Table 5 Sort

Parameter

Mandatory

Type

Description

order_by

Yes

Array of strings

List of sorted fields. Fields in this list are sorted based on the specified order.

order

Yes

String

Sorting order.

The value can be:

  • asc (ascending order)

  • desc (descending order)

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

events

Array of Events objects

Alarm information.

page_info

PageInfo object

Pagination details.

Table 7 Events

Parameter

Type

Description

annotations

Annotations object

Alert details.

metadata

Metadata object

Alarm information.

arrives_at

Long

Arrival time (timestamp).

ends_at

Long

Alarm clearance time (timestamp).

id

String

Alarm ID.

starts_at

Long

Alarm generation time (timestamp).

timeout

Long

Time when an alarm is automatically cleared (timestamp).

type

String

Alarm rule type (SQL/keyword).

Table 8 Annotations

Parameter

Type

Description

message

String

Alarm list details.

log_info

String

Log group/stream ID.

current_value

String

Current value.

old_annotations

String

Original data of (SQL/keyword) alarm details.

Table 9 Metadata

Parameter

Type

Description

event_type

String

Alarm type.

event_id

String

Alarm ID.

event_severity

String

Alarm severity.

event_name

String

Alarm name.

resource_type

String

Resource type.

resource_id

String

Log group/stream name.

resource_provider

String

Alarm source.

lts_alarm_type

String

Alarm rule type (SQL/keyword).

Table 10 PageInfo

Parameter

Type

Description

next_marker

String

Address of the next page. If this parameter is left empty, no data is displayed on the next page.

previous_marker

String

Address of the previous page.

current_count

String

Number of items returned on this page.

Status code: 400

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

Querying the active or historical alarm list

POST https://{endpoint}/v2/{project_id}/{domain_id}/lts/alarms/sql-alarm/query?type=active_alert

{
  "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" : {
      "current_value" : "{\"pv\":30}",
      "log_info" : "[{\"log_group_id\":\"50bcab14-xxxx-xxxx-xxxx-41ae4a6e3401\",\"log_group_name\":\"lts-test-group\",\"log_group_name_alias\":\"lts-test-group\",\"log_stream_id\":\"90727e60-xxxx-xxxx-xxxx-19ba53adcbc5\",\"log_stream_name\":\"lts-test-topic\",\"log_stream_name_alias\":\"lts-test-topic\"}]",
      "message" : "{\"alarm_action_rule_name\":\"testlts\",\"alarm_rule_alias\":\"lts001\",\"alarm_rule_id\":\"2ef849e9-afb4-4983-9197-9049c3460b9d\",\"alarm_rule_name\":\"lts001\",\"closed_alarm_time\":0,\"condition_expression\":\"pv > 0\",\"condition_expressions\":[{\"condition_expression\":\"pv > 0\"}],\"create_time\":0,\"domain_id\":\"1d26cc8c86a840e28a4f8dxxxxxxxxxx\",\"frequency\":{\"day_of_week\":1,\"fixed_rate\":1,\"fixed_rate_unit\":\"minute\",\"hour_of_day\":0,\"type\":\"FIXED_RATE\"},\"is_css_sql\":true,\"ltsAlarmInfos\":[{\"conditions\":[],\"is_time_range_relative\":true,\"log_group_id\":\"50bcab14-xxxx-xxxx-xxxx-41ae4a6e3401\",\"log_group_name\":\"lts-test-group\",\"log_group_name_alias\":\"lts-test-group\",\"log_stream_id\":\"90727e60-xxxx-xxxx-xxxx-19ba53adcbc5\",\"log_stream_name\":\"lts-test-topic\",\"log_stream_name_alias\":\"lts-test-topic\",\"search_time_range\":5,\"search_time_range_unit\":\"minute\",\"sql\":\"* | SELECT count(*) as pv\",\"sql_request_title\":\"\"}],\"notification_frequency\":0,\"projectId\":\"\",\"status\":\"RUNNING\",\"topics\":[],\"type\":\"sql\",\"update_time\":0,\"whether_recovery_policy\":false}"
    },
    "metadata" : {
      "event_type" : "alarm",
      "event_id" : "2ef849e9-xxxx-xxxx-xxxx-9049c3460b9d",
      "lts_alarm_type" : "search_analysis",
      "event_severity" : "Critical",
      "resource_type" : "Log group/stream.",
      "event_name" : "lts001",
      "resource_id" : "lts-test-group/lts-test-topic",
      "event_subtype" : "sql",
      "resource_provider" : "LTS"
    },
    "type" : "search_analysis"
  } ]
}

Status code: 400

Response content.

{
  "error_code" : "LTS.2005",
  "error_msg" : "Find alarm error start_time or end_tim must not be empty."
}

Status code: 500

Response content.

{
  "error_code" : "LTS.0010",
  "error_msg" : "Internal Server Error"
}

Status Codes

Status Code

Description

200

The request is successful.

400

Response content.

500

Response content.

Error Codes

See Error Codes.