Modifying a SQL Alarm Rule
Function
This API is used to modify a SQL alarm rule.
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:updateSqlAlarmRule
Write
alarmRule *
-
- lts:sqlalarmrules:put
-
URI
PUT /v2/{project_id}/lts/alarms/sql-alarm-rule
|
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
|
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 |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
sql_alarm_rule_id |
Yes |
String |
Definition SQL alarm rule ID. Constraints N/A Range N/A Default Value N/A |
|
sql_alarm_rule_name |
Yes |
String |
Definition SQL alarm rule name. Constraints
Range N/A Default Value N/A |
|
alarm_rule_alias |
No |
String |
Definition SQL alarm rule alias. Constraints
Range N/A Default Value N/A |
|
is_css_sql |
No |
Boolean |
Definition Whether to use the SQL query with the pipe character (|). Constraints N/A Range
Default Value false |
|
sql_alarm_rule_description |
No |
String |
Definition Brief description of a SQL alarm rule. Constraints N/A Range A maximum of 128 characters is allowed. Default Value N/A |
|
sql_requests |
Yes |
Array of SqlRequest objects |
Definition SQL alarm details. Constraints N/A |
|
frequency |
Yes |
CreateSqlAlarmRuleFrequency object |
Definition SQL alarm query frequency. Constraints N/A |
|
condition_expression |
Yes |
String |
Definition Condition expression for triggering an alarm. Constraints
Range N/A Default Value N/A |
|
sql_alarm_level |
Yes |
String |
Definition SQL alarm severity. Constraints The value cannot contain only digits or start with a digit. Range
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 |
|
trigger_condition_count |
No |
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. When this count is reached within a specified number of queries, a SQL alarm is triggered. Constraints
Range N/A Default Value N/A |
|
trigger_condition_frequency |
No |
Integer |
Definition Alarm triggering condition: number of queries. It refers to the number of queries set in the advanced settings. When the value of trigger_condition_count is reached within a specified number of queries, a SQL alarm is triggered. Constraints
Range Minimum value: 1 Maximum value: 10 Default Value N/A |
|
whether_recovery_policy |
No |
Boolean |
Definition Whether to configure an alarm restoration policy. If this policy is met, an alarm restoration notification is sent. Constraints N/A Range
Default Value false |
|
recovery_policy |
No |
Integer |
Definition Number of consecutive queries in which the alarm's trigger condition must not be met. If alarm restoration notification is enabled and the trigger condition has not been met for the specified number of last queries, an alarm restoration notification is sent. Constraints N/A Range
Default Value N/A |
|
notification_frequency |
Yes |
Integer |
Definition Alarm notification frequency. The options are immediate, every 5 minutes, every 10 minutes, every 15 minutes, every 30 minutes, every 1 hour, every 3 hours, and every 6 hours. Immediate indicates that a notification is sent once an alarm is generated. Every 10 minutes indicates that the minimum interval between two notifications is 10 minutes, preventing alarm storms. Constraints N/A Range
Default Value N/A |
|
alarm_action_rule_name |
No |
String |
Definition Alarm action rule name. Constraints N/A Range
Default Value N/A |
|
tags |
No |
Array of tagsRequestBody objects |
Definition Alarm tag information. A tag is a key-value pair. Each key is paired with its corresponding value. Constraints N/A |
|
enterprise_project_id |
No |
String |
Definition Enterprise project ID. Constraints N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
log_stream_id |
Yes |
String |
Definition Log stream ID. For details about how to obtain it, see Obtaining Log Group and Log Stream IDs. Constraints N/A Range N/A Default Value N/A |
|
log_stream_name |
No |
String |
Definition Log stream name. If a log group contains more than one log stream, you can select multiple log streams when creating a keyword alarm rule. Constraints N/A Range
Default Value N/A |
|
log_group_id |
Yes |
String |
Definition Log stream ID. For details about how to obtain it, see Obtaining Log Group and Log Stream IDs. Constraints N/A Range N/A Default Value N/A |
|
log_group_name |
No |
String |
Definition Log group name. Constraints N/A Range N/A Default Value N/A |
|
sql |
Yes |
String |
Definition SQL statement. Constraints N/A Range N/A Default Value N/A |
|
search_time_range |
No |
Integer |
Definition Time range for querying the latest data when the alarm rule executes. Constraints
Range Minimum value: 1 Maximum value: 60 Default Value 1 |
|
search_time_range_unit |
No |
String |
Definition Unit of the alarm query time range. (This field is currently not available to users. It will be available after AOM launches this function.) Constraints
Range Default Value minute |
|
custom_date |
No |
CustomDate object |
Definition Customize the alarm query time range based on the time relative to the alarm rule's execution time. (This field is currently not available to users. It will be available after AOM launches this function.) Constraints N/A |
|
is_time_range_relative |
No |
Boolean |
Definition Whether the alarm rule queries logs using a relative time range or an absolute (exact) hour. (This field is currently not available to users. It will be available after AOM launches this function.) Constraints N/A Range
Default Value true |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
start |
Yes |
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
|
|
start_unit |
Yes |
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
Default Value minute |
|
end |
Yes |
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
|
|
end_unit |
Yes |
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
Default Value minute |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
type |
Yes |
String |
Definition Query frequency type of alarms. Constraints N/A Range
Default Value N/A |
|
cron_expr |
No |
String |
Definition Cron expression. This parameter is mandatory when type is set to CRON. Cron expressions use the 24-hour format and are precise down to the minute. Examples:
Constraints N/A Range N/A Default Value N/A |
|
hour_of_day |
No |
Integer |
Definition Every hour of every day. This parameter is mandatory when type is set to DAILY or HOURLY. Constraints N/A Range DAILY: 00:00 to 23:00 Default Value N/A |
|
day_of_week |
No |
Integer |
Definition Weekly. This parameter is mandatory when type is set to WEEKLY. Constraints N/A Range 00:00 to 23:00 on Sunday to Saturday Default Value N/A |
|
fixed_rate |
No |
Integer |
Definition Fixed interval. This parameter is mandatory when type is set to FIXED_RATE. Constraints N/A Range
Default Value N/A |
|
fixed_rate_unit |
No |
String |
Definition Unit of the fixed interval. Constraints N/A Range
Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
key |
Yes |
String |
Definition Tag key. Constraints
Range Each tag key can contain up to 128 characters, including only letters, digits, spaces, and special characters (_.:=+-@). Do not start or end with a space, nor start with sys. Default Value N/A |
|
value |
No |
String |
Definition Tag value. Constraints A tag is a key-value pair. Each key is paired with its corresponding value. Range
Default Value N/A |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
sql_alarm_rule_name |
String |
Definition Original name of the SQL alarm rule. Range N/A |
|
alarm_rule_alias |
String |
Definition SQL alarm rule alias. Range N/A |
|
is_css_sql |
Boolean |
Definition Whether to use the SQL query with the pipe character (|). Range N/A |
|
projectId |
String |
Definition Project ID. Range N/A |
|
sql_alarm_rule_id |
String |
Definition SQL alarm rule ID. Range N/A |
|
sql_alarm_rule_description |
String |
Definition SQL alarm rule description. Range N/A |
|
sql_requests |
Array of SqlRequestResponse objects |
Definition SQL details. |
|
frequency |
FrequencyRespBody object |
Definition Query frequency of alarms. |
|
condition_expression |
String |
Definition Alarm triggering condition expression. Range N/A |
|
sql_alarm_level |
String |
Definition Alarm severity. Range
|
|
sql_alarm_send |
Boolean |
Definition Whether to send an alarm. Range
|
|
domain_id |
String |
Definition Account ID. Range N/A |
|
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 Triggering condition: number of queries to be evaluated for an alarm. Range N/A |
|
whether_recovery_policy |
Boolean |
Definition Whether to send notifications when an alarm is restored. Range
|
|
recovery_policy |
Integer |
Definition Number of consecutive queries in which an alarm's trigger condition must not be met for the alarm to be considered restored. Range N/A |
|
notification_frequency |
Integer |
Definition Alarm notification frequency. The options are immediate, every 5 minutes, every 10 minutes, every 15 minutes, every 30 minutes, every 1 hour, every 3 hours, and every 6 hours. Immediate indicates that a notification is sent once an alarm is generated. Every 10 minutes indicates that the minimum interval between two notifications is 10 minutes, preventing alarm storms. Range N/A |
|
alarm_action_rule_name |
String |
Definition Alarm action rule name. Range N/A |
|
tags |
Array of tagsResBody objects |
Definition Alarm tag information. A tag is a key-value pair. Each key is paired with its corresponding value. |
|
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
|
|
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
Default Value true |
|
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
|
|
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
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
|
|
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
Default Value minute |
|
Parameter |
Type |
Description |
|---|---|---|
|
type |
String |
Definition Query frequency type of alarms. Range
|
|
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
|
|
Parameter |
Type |
Description |
|---|---|---|
|
key |
String |
Definition Tag key. Range N/A |
|
value |
String |
Definition Tag value. Range N/A |
Status code: 400
|
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 |
Status code: 500
|
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
Modify a SQL alarm rule.
PUT https://{endpoint}/v2/{project_id}/lts/alarms/sql-alarm-rule
{
"sql_alarm_rule_id" : "",
"sql_alarm_rule_name" : "huawei",
"is_css_sql" : false,
"alarm_rule_alias" : "zhangsan",
"sql_alarm_rule_description" : "huawei",
"sql_requests" : [ {
"log_stream_id" : "1",
"log_group_id" : "1",
"sql" : "select count(*) as t",
"sql_request_title" : "demo",
"search_time_range" : 10,
"search_time_range_unit" : "minute"
} ],
"frequency" : {
"type" : "FIXED_RATE",
"cron_expr" : "",
"hour_of_day" : 0,
"day_of_week" : 0,
"fixed_rate" : 10,
"fixed_rate_unit" : "minute"
},
"condition_expression" : "t>0",
"sql_alarm_level" : "Critical",
"sql_alarm_send" : true,
"sql_alarm_send_code" : 0,
"domain_id" : "",
"notification_frequency" : 5,
"alarm_action_rule_name" : ""
}
Example Responses
Status code: 200
The request is successful.
{
"sql_alarm_rule_id" : "",
"sql_alarm_rule_name" : "huawei",
"alarm_rule_alias" : "zhangsan",
"is_css_sql" : false,
"sql_alarm_rule_description" : "huawei",
"sql_requests" : [ {
"log_stream_id" : "1",
"log_stream_name" : "huawei",
"log_group_name" : "huawei",
"log_group_id" : "1",
"sql" : "select count(*) as t",
"sql_request_title" : "demo",
"search_time_range" : 10,
"search_time_range_unit" : "minute"
} ],
"frequency" : {
"type" : "FIXED_RATE",
"cron_expr" : "",
"hour_of_day" : 0,
"day_of_week" : 0,
"fixed_rate" : 10,
"fixed_rate_unit" : "minute"
},
"condition_expression" : "t>0",
"sql_alarm_level" : "Critical",
"sql_alarm_send" : true,
"domain_id" : "",
"notification_frequency" : 5,
"alarm_action_rule_name" : ""
}
Status code: 400
Invalid request. Modify the request based on the description in error_msg before a retry.
{
"error_code" : "LTS.2005",
"error_msg" : "Alarm rule params validator error."
}
Status code: 500
The server has received the request but encountered an internal error.
{
"error_code" : "LTS.2003",
"error_msg" : "Failed to update alarm rule."
}
SDK Sample Code
The SDK sample code is as follows.
Modify a SQL alarm rule.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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.*; import java.util.List; import java.util.ArrayList; public class UpdateSqlAlarmRuleSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); UpdateSqlAlarmRuleRequest request = new UpdateSqlAlarmRuleRequest(); UpdateSqlAlarmRuleRequestBody body = new UpdateSqlAlarmRuleRequestBody(); CreateSqlAlarmRuleFrequency frequencybody = new CreateSqlAlarmRuleFrequency(); frequencybody.withType(CreateSqlAlarmRuleFrequency.TypeEnum.fromValue("FIXED_RATE")) .withCronExpr("") .withHourOfDay(0) .withDayOfWeek(0) .withFixedRate(10) .withFixedRateUnit(CreateSqlAlarmRuleFrequency.FixedRateUnitEnum.fromValue("minute")); List<SqlRequest> listbodySqlRequests = new ArrayList<>(); listbodySqlRequests.add( new SqlRequest() .withLogStreamId("1") .withLogGroupId("1") .withSql("select count(*) as t") .withSearchTimeRange(10) .withSearchTimeRangeUnit(SqlRequest.SearchTimeRangeUnitEnum.fromValue("minute")) ); body.withAlarmActionRuleName(""); body.withNotificationFrequency(UpdateSqlAlarmRuleRequestBody.NotificationFrequencyEnum.NUMBER_5); body.withDomainId(""); body.withSqlAlarmLevel(UpdateSqlAlarmRuleRequestBody.SqlAlarmLevelEnum.fromValue("Critical")); body.withConditionExpression("t>0"); body.withFrequency(frequencybody); body.withSqlRequests(listbodySqlRequests); body.withSqlAlarmRuleDescription("huawei"); body.withIsCssSql(false); body.withAlarmRuleAlias("zhangsan"); body.withSqlAlarmRuleName("huawei"); body.withSqlAlarmRuleId(""); request.withBody(body); try { UpdateSqlAlarmRuleResponse response = client.updateSqlAlarmRule(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()); } } } |
Modify a SQL alarm rule.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateSqlAlarmRuleRequest() frequencybody = CreateSqlAlarmRuleFrequency( type="FIXED_RATE", cron_expr="", hour_of_day=0, day_of_week=0, fixed_rate=10, fixed_rate_unit="minute" ) listSqlRequestsbody = [ SqlRequest( log_stream_id="1", log_group_id="1", sql="select count(*) as t", search_time_range=10, search_time_range_unit="minute" ) ] request.body = UpdateSqlAlarmRuleRequestBody( alarm_action_rule_name="", notification_frequency=5, domain_id="", sql_alarm_level="Critical", condition_expression="t>0", frequency=frequencybody, sql_requests=listSqlRequestsbody, sql_alarm_rule_description="huawei", is_css_sql=False, alarm_rule_alias="zhangsan", sql_alarm_rule_name="huawei", sql_alarm_rule_id="" ) response = client.update_sql_alarm_rule(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Modify a SQL alarm rule.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateSqlAlarmRuleRequest{} cronExprFrequency:= "" hourOfDayFrequency:= int32(0) dayOfWeekFrequency:= int32(0) fixedRateFrequency:= int32(10) fixedRateUnitFrequency:= model.GetCreateSqlAlarmRuleFrequencyFixedRateUnitEnum().MINUTE frequencybody := &model.CreateSqlAlarmRuleFrequency{ Type: model.GetCreateSqlAlarmRuleFrequencyTypeEnum().FIXED_RATE, CronExpr: &cronExprFrequency, HourOfDay: &hourOfDayFrequency, DayOfWeek: &dayOfWeekFrequency, FixedRate: &fixedRateFrequency, FixedRateUnit: &fixedRateUnitFrequency, } searchTimeRangeSqlRequests:= int32(10) searchTimeRangeUnitSqlRequests:= model.GetSqlRequestSearchTimeRangeUnitEnum().MINUTE var listSqlRequestsbody = []model.SqlRequest{ { LogStreamId: "1", LogGroupId: "1", Sql: "select count(*) as t", SearchTimeRange: &searchTimeRangeSqlRequests, SearchTimeRangeUnit: &searchTimeRangeUnitSqlRequests, }, } alarmActionRuleNameUpdateSqlAlarmRuleRequestBody:= "" sqlAlarmRuleDescriptionUpdateSqlAlarmRuleRequestBody:= "huawei" isCssSqlUpdateSqlAlarmRuleRequestBody:= false alarmRuleAliasUpdateSqlAlarmRuleRequestBody:= "zhangsan" request.Body = &model.UpdateSqlAlarmRuleRequestBody{ AlarmActionRuleName: &alarmActionRuleNameUpdateSqlAlarmRuleRequestBody, NotificationFrequency: model.GetUpdateSqlAlarmRuleRequestBodyNotificationFrequencyEnum().E_5, DomainId: "", SqlAlarmLevel: model.GetUpdateSqlAlarmRuleRequestBodySqlAlarmLevelEnum().CRITICAL, ConditionExpression: "t>0", Frequency: frequencybody, SqlRequests: listSqlRequestsbody, SqlAlarmRuleDescription: &sqlAlarmRuleDescriptionUpdateSqlAlarmRuleRequestBody, IsCssSql: &isCssSqlUpdateSqlAlarmRuleRequestBody, AlarmRuleAlias: &alarmRuleAliasUpdateSqlAlarmRuleRequestBody, SqlAlarmRuleName: "huawei", SqlAlarmRuleId: "", } response, err := client.UpdateSqlAlarmRule(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. |
|
400 |
Invalid request. Modify the request based on the description in error_msg before a retry. |
|
500 |
The server has received the request but encountered an internal error. |
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