Updated on 2025-11-14 GMT+08:00

Querying SQL Alarm Rules

Function

This API is used to query a SQL alarm.

Calling Method

For details, see Calling APIs.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    lts:alarmRule:listSqlAlarmRule

    List

    -

    -

    • lts:sqlalarmrules:get

    -

URI

GET /v2/{project_id}/lts/alarms/sql-alarm-rule

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

Request Parameters

Table 2 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

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

sql_alarm_rules

Array of SqlAlarmRuleRespList objects

Definition

SQL alarm rule information.

Table 4 SqlAlarmRuleRespList

Parameter

Type

Description

sql_alarm_rule_name

String

Definition

SQL alarm rule name.

Range

N/A

is_css_sql

Boolean

Definition

Whether to use the SQL query with the pipe character (|).

Range

  • true: Search | Analysis alarm rule.

  • false: SQL alarm rule.

sql_alarm_rule_id

String

Definition

SQL alarm rule ID.

Range

N/A

sql_alarm_rule_description

String

Definition

Brief description of a SQL alarm rule.

Range

N/A

sql_requests

Array of SqlRequestResponse objects

Definition

SQL alarm rule information.

frequency

FrequencyRespBody object

Definition

SQL alarm query frequency.

condition_expression

String

Definition

Condition expression for triggering an alarm.

Range

N/A

topics

Array of Topics objects

Definition

SMN topic information.

sql_alarm_level

String

Definition

Alarm severity.

Range

  • Info

  • Minor

  • Major

  • Critical

domain_id

String

Definition

Account ID.

Range

N/A

create_time

Long

Definition

Time when the SQL alarm rule was created (timestamp in milliseconds).

Range

N/A

update_time

Long

Definition

Time when the SQL alarm rule was modified (timestamp in milliseconds).

Range

N/A

template_name

String

Definition

Message template name.

Range

N/A

status

String

Definition

Alarm status.

Range

  • Triggered

  • Restored

trigger_condition_count

Integer

Definition

Alarm triggering condition: number of times the condition is met. It specifies the number of times a specified SQL statement's condition must be met to trigger an alarm.

Range

N/A

trigger_condition_frequency

Integer

Definition

Alarm triggering condition: number of queries. It refers to the number of queries set in the advanced settings.

Range

N/A

whether_recovery_policy

Boolean

Definition

Whether to configure an alarm restoration policy. If this policy is met, an alarm restoration notification is sent.

Range

  • true: configures an alarm restoration policy.

  • false: does not configure an alarm restoration policy.

recovery_policy

Integer

Definition

Number of consecutive queries in which the alarm's trigger condition must not be met.

Range

N/A

notification_frequency

Integer

Definition

Alarm notification frequency.

Range

  • 0*

  • 5

  • 10

  • 15

  • 30

  • 60

  • 180

  • 630

alarm_action_rule_name

String

Definition

Alarm action rule name.

Range

N/A

tags

Array of tagsResBody objects

Definition

Alarm tag information.

Table 5 SqlRequestResponse

Parameter

Type

Description

log_stream_id

String

Definition

Log stream ID.

Range

N/A

log_stream_name

String

Definition

Log stream name.

Range

N/A

log_group_id

String

Definition

Log stream ID.

Range

N/A

log_group_name

String

Definition

Log group name.

Range

N/A

sql

String

Definition

SQL statement.

Range

N/A

sql_request_title

String

Definition

Name of the chart associated with the alarms.

Range

N/A

search_time_range

Integer

Definition

Time range for querying the latest data when an alarm task is executed.

Range

N/A

search_time_range_unit

String

Definition

Unit of the alarm query time range.

Range

  • minute

  • hour

custom_date

CustomDate object

Definition

Customize the alarm query time range based on the time relative to the alarm rule's execution time.

Constraints

N/A

is_time_range_relative

Boolean

Definition

Whether the alarm rule queries logs using a relative time range or an absolute (exact) hour.

Constraints

N/A

Range

  • true: relative time

  • false: exact hour

Default Value

true

Table 6 CustomDate

Parameter

Type

Description

start

Integer

Definition

Value of the offset of the query start time relative to the planned alarm rule execution time.

Constraints

The valid value range for the start field is determined by the start_unit field. The total time converted from the start value and start_unit cannot exceed one day.

Range

If start_unit is set to second, the value of start ranges from 1 to 86400.

If start_unit is set to minute, the value of start ranges from 1 to 1440.

If start_unit is set to hour, the value of start ranges from 1 to 24.

Default Value

  • None

start_unit

String

Definition

Unit of the offset of the query start time relative to the planned alarm rule execution time.

Constraints

When is_time_range_relative is set to false, start_unit cannot be set to second.

Range

  • hour

  • minute

  • second

Default Value

minute

end

Integer

Definition

Value of the offset of the query end time relative to the planned alarm rule execution time.

Constraints

The valid value range for the end field is determined by the end_unit field. The total time converted from the end value and end_unit cannot exceed one day.

Range

If end_unit is set to second, the value of end ranges from 0 to 86399.

If end_unit is set to minute, the value of end ranges from 0 to 1439.

If end_unit is set to hour, the value of end ranges from 0 to 23.

Default Value

  • None

end_unit

String

Definition

Unit of the offset of the query end time relative to the planned alarm rule execution time.

Constraints

When is_time_range_relative is set to false, end_unit cannot be set to second.

Range

  • hour

  • minute

  • second

Default Value

minute

Table 7 FrequencyRespBody

Parameter

Type

Description

type

String

Definition

Query frequency type of alarms.

Range

  • CRON: cron expression

  • HOURLY: every hour

  • DAILY: every day

  • WEEKLY: every week

  • FIXED_RATE: fixed interval

cron_expr

String

Definition

Cron expression. This parameter is returned when type is set to CRON. Cron expressions use the 24-hour format and are precise down to the minute.

Range

N/A

hour_of_day

Integer

Definition

Every hour of every day. This parameter is returned when type is set to DAILY or HOURLY.

Range

N/A

day_of_week

Integer

Definition

Weekly. This parameter is returned when type is set to WEEKLY.

Range

N/A

fixed_rate

Integer

Definition

Fixed interval. This parameter is returned when type is set to FIXED_RATE.

Range

N/A

fixed_rate_unit

String

Definition

Unit of the fixed interval.

Range

  • minute

  • hour

Table 8 Topics

Parameter

Type

Description

name

String

Definition

SMN topic name.

Range

N/A

topic_urn

String

Definition

Unique resource ID of the SMN topic.

Range

N/A

display_name

String

Definition

Sender name displayed in an email.

Range

N/A

push_policy

Integer

Definition

Message push policy. Currently, this attribute is not modifiable. Support for modifying this setting will be added in a future update.

Range

  • 0: Failed messages will be retained in the failure queue.

  • 1: Failed messages will be discarded.

Table 9 tagsResBody

Parameter

Type

Description

key

String

Definition

Tag key.

Range

N/A

value

String

Definition

Tag value.

Range

N/A

Status code: 500

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Definition

Error code. For details, see Error Codes.

Range

N/A

error_msg

String

Definition

Error message.

Range

N/A

Example Requests

Query SQL alarm rules.

GET https://{endpoint}/v2/{project_id}/lts/alarms/sql-alarm-rule

/v2/{project_id}/lts/alarms/sql-alarm-rule

Example Responses

Status code: 200

The request is successful.

{
  "sql_alarm_rules" : [ {
    "sql_alarm_rule_name" : "string",
    "is_css_sql" : false,
    "sql_alarm_rule_id" : "string",
    "sql_alarm_rule_description" : "string",
    "sql_requests" : [ {
      "log_stream_id" : "string",
      "log_stream_name" : "string",
      "log_group_id" : "string",
      "log_group_name" : "string",
      "sql" : "string",
      "sql_request_title" : "string",
      "search_time_range" : 0,
      "search_time_range_unit" : "minute"
    } ],
    "frequency" : {
      "type" : "CRON",
      "cron_expr" : "string",
      "hour_of_day" : 0,
      "day_of_week" : 0,
      "fixed_rate" : 0,
      "fixed_rate_unit" : "minute"
    },
    "condition_expression" : "string",
    "sql_alarm_level" : "Info",
    "domain_id" : "string",
    "create_time" : 0,
    "update_time" : 0,
    "template_name" : "Message template name.",
    "status" : "RUNNING",
    "trigger_condition_count" : "1",
    "trigger_condition_frequency" : "1",
    "whether_recovery_policy" : false,
    "recovery_policy" : "3",
    "notification_frequency" : 5,
    "alarm_action_rule_name" : ""
  } ]
}

Status code: 500

The server has received the request but encountered an internal error.

{
  "error_code" : "LTS.2008",
  "error_msg" : "Find Alarm rule failed."
}

Status Codes

Status Code

Description

200

The request is successful.

500

The server has received the request but encountered an internal error.

Error Codes

See Error Codes.