Updated on 2024-12-20 GMT+08:00

Querying SQL Alarm Rules

Function

This API is used to query a SQL alarm.

Calling Method

For details, see Calling APIs.

URI

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

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

Request Parameters

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

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

sql_alarm_rules

Array of SqlAlarmRuleRespList objects

SQL alarms.

Table 4 SqlAlarmRuleRespList

Parameter

Type

Description

sql_alarm_rule_name

String

SQL alarm name.

Minimum: 1

Maximum: 64

is_css_sql

Boolean

Whether to use the SQL query with the pipe character.

Default: false

sql_alarm_rule_id

String

SQL alarm rule ID.

Minimum: 36

Maximum: 36

sql_alarm_rule_description

String

SQL alarm description.

Minimum: 0

Maximum: 64

sql_requests

Array of SqlRequest objects

SQL details.

frequency

FrequencyRespBody object

Alarm statistical period.

condition_expression

String

Condition expression.

Minimum: 1

Maximum: 1024

topics

Array of Topics objects

Topic information.

sql_alarm_level

String

Alarm severity.

sql_alarm_send

Boolean

Whether to send an alarm.

domain_id

String

domainId

Minimum: 32

Maximum: 32

create_time

Long

Creation time (timestamp in milliseconds).

Minimum: 13

Maximum: 13

update_time

Long

Update time (timestamp in milliseconds).

Minimum: 13

Maximum: 13

template_name

String

Message template name.

status

String

Alarm status.

trigger_condition_count

Integer

Number of queries in which the triggering condition is met. The default value is 1.

trigger_condition_frequency

Integer

Number of queries in which the triggering condition is met. The default value is 1.

whether_recovery_policy

Boolean

Whether to enable the alarm clearance notification. The default value is false.

recovery_policy

Integer

Number of queries in which the triggering condition is not met. The alarm is cleared when this number reaches the value (3 by default) of this parameter.

notification_frequency

Integer

Notification frequency, in minutes.

alarm_action_rule_name

String

Alarm action rule name.

NOTE:

Set alarm_action_rule_name or notification_save_rule. If you set both of them, the value of alarm_action_rule_name is prioritized.

Table 5 SqlRequest

Parameter

Type

Description

is_time_range_relative

Boolean

The time range is relative.

log_stream_id

String

Log stream ID.

Minimum: 36

Maximum: 36

log_stream_name

String

Log stream name.

Minimum: 1

Maximum: 64

log_group_id

String

Log group ID.

Minimum: 36

Maximum: 36

log_group_name

String

Log group name.

Minimum: 1

Maximum: 64

sql

String

SQL statement.

Minimum: 1

Maximum: 1024

sql_request_title

String

Chart name.

Minimum: 1

Maximum: 64

search_time_range

Integer

Time range for querying the latest data when a task is executed. If search_time_range_unit is set to minute, the maximum value is 60. If search_time_range_unit is set to hour, the maximum value is 24.

Minimum: 1

Maximum: 60

search_time_range_unit

String

Query time unit.

Table 6 FrequencyRespBody

Parameter

Type

Description

type

String

Time type.

cron_expr

String

This field is used when type is set to CRON.

Minimum: 1

Maximum: 1024

hour_of_day

Integer

This field is used when type is set to DAILY or WEEKLY.

day_of_week

Integer

This field is used when type is set to WEEKLY (Sunday to Saturday).

fixed_rate

Integer

This field is used when type is set to FIXED_RATE. If the unit of fixed_rate_unit is minute, the maximum value is 60. If the unit is hour, the maximum value is 24.

fixed_rate_unit

String

Enumerated values of the time unit:

Table 7 Topics

Parameter

Type

Description

name

String

Topic name.

Minimum: 1

Maximum: 1024

topic_urn

String

Specifies the resource identifier of the topic, which is unique.

Minimum: 1

Maximum: 1024

display_name

String

Specifies the topic display name, which is presented as the name of the email sender in email messages.

Minimum: 1

Maximum: 1024

push_policy

Integer

Specifies the message push policy.

Minimum: 1

Maximum: 1024

Status code: 500

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

Querying a SQL alarm rule

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",
    "topics" : [ {
      "name" : "string",
      "topic_urn" : "string",
      "display_name" : "string",
      "push_policy" : 0
    } ],
    "sql_alarm_level" : "Info",
    "sql_alarm_send" : true,
    "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.