Modifying a Keyword Alarm Rule
Function
This API is used to modify a keyword alarm.
Calling Method
For details, see Calling APIs.
URI
PUT /v2/{project_id}/lts/alarms/keywords-alarm-rule
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. |
Request 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. |
Content-Type |
Yes |
String |
Set this parameter to application/json;charset=UTF-8. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
keywords_alarm_rule_id |
Yes |
String |
Keyword alarm rule ID. |
keywords_alarm_rule_name |
Yes |
String |
Original rule name, which cannot be changed. |
alarm_rule_alias |
No |
String |
Rule name. |
keywords_alarm_rule_description |
No |
String |
Keyword alarm description. |
keywords_requests |
Yes |
Array of KeywordsRequest objects |
Keyword details. |
frequency |
Yes |
Frequency object |
Alarm statistical period. |
keywords_alarm_level |
Yes |
String |
Alarm severity. |
keywords_alarm_send |
Yes |
Boolean |
Whether to send an alarm. |
keywords_alarm_send_code |
Yes |
Integer |
Subject. 0: unchanged; 1: added; 2: modified; 3: deleted. |
domain_id |
Yes |
String |
domainId |
notification_save_rule |
No |
SqlNotificationSaveRule object |
Topic |
trigger_condition_count |
No |
Integer |
Number of times that log events meet the trigger condition. The default value is 1. |
trigger_condition_frequency |
No |
Integer |
Number of queries in which the triggering condition is met. The default value is 1. |
whether_recovery_policy |
No |
Boolean |
Whether to enable the alarm clearance notification. The default value is false. |
recovery_policy |
No |
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 |
Yes |
Integer |
Notification frequency, in minutes. |
alarm_action_rule_name |
No |
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. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
log_stream_id |
Yes |
String |
Log stream ID. |
log_stream_name |
No |
String |
Log stream name. |
log_group_id |
Yes |
String |
Log group ID. |
log_group_name |
No |
String |
Log group name. |
keywords |
Yes |
String |
Keyword |
condition |
Yes |
String |
Condition |
number |
Yes |
Integer |
Row |
search_time_range |
Yes |
Integer |
Time range for querying the latest data when a task is executed. The maximum value is 60 and the minimum is 1 if the unit is minute. The maximum is 24 and the minimum is 1 if the unit is hour. |
search_time_range_unit |
Yes |
String |
Query time unit. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
type |
Yes |
String |
Time type. |
cron_expr |
No |
String |
This field is used when type is set to CRON. |
hour_of_day |
No |
Integer |
This field is used when type is set to DAILY or WEEKLY. DAILY ranges from 0 to 23. WEEKLY ranges from 0 to 23. |
day_of_week |
No |
Integer |
This field is used when type is set to WEEKLY (Sunday to Saturday). |
fixed_rate |
No |
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 value ranges from 5 to 24. |
fixed_rate_unit |
No |
String |
Time unit. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
language |
Yes |
String |
Language of the preference. |
timezone |
No |
String |
Time zone of the preference. |
user_name |
Yes |
String |
Username. |
topics |
Yes |
Array of Topics objects |
Topic information. |
template_name |
Yes |
String |
Message template name. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Topic name. |
topic_urn |
Yes |
String |
Specifies the resource identifier of the topic, which is unique. |
display_name |
No |
String |
Specifies the topic display name, which is presented as the name of the email sender in email messages. |
push_policy |
No |
Integer |
Specifies the message push policy. |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
keywords_alarm_rule_id |
String |
Keyword alarm ID. |
keywords_alarm_rule_name |
String |
Original rule name. |
alarm_rule_alias |
String |
Rule name. |
keywords_alarm_rule_description |
String |
Keyword alarm description. |
keywords_requests |
Array of KeywordsResBody objects |
Keyword details. |
frequency |
FrequencyRespBody object |
Alarm statistical period. |
keywords_alarm_level |
String |
Alarm severity. |
keywords_alarm_send |
Boolean |
Whether to send an alarm. |
domain_id |
String |
domainId |
create_time |
Long |
Creation time (timestamp in milliseconds). |
update_time |
Long |
Update time (timestamp in milliseconds). |
language |
String |
Language of information added to emails. |
projectId |
String |
Project ID. |
topics |
Array of Topics objects |
Topic. |
condition_expression |
String |
Description. |
indexId |
String |
Index ID. |
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. |
Parameter |
Type |
Description |
---|---|---|
log_stream_id |
String |
Log stream ID. |
log_stream_name |
String |
Log stream name. |
log_group_id |
String |
Log group ID. |
log_group_name |
String |
Log group name. |
keywords |
String |
Keyword |
condition |
String |
Condition |
number |
Integer |
Number of lines. |
search_time_range |
Integer |
Time range for querying the latest data when a task is executed. The maximum value is 60. |
search_time_range_unit |
String |
Query time unit. |
Parameter |
Type |
Description |
---|---|---|
type |
String |
Time type. |
cron_expr |
String |
This field is used when type is set to CRON. |
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: |
Parameter |
Type |
Description |
---|---|---|
name |
String |
Topic name. |
topic_urn |
String |
Specifies the resource identifier of the topic, which is unique. |
display_name |
String |
Specifies the topic display name, which is presented as the name of the email sender in email messages. |
push_policy |
Integer |
Specifies the message push policy. |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. |
error_msg |
String |
Error message. |
Example Requests
Modifying a keyword alarm rule
PUT https://{endpoint}/v2/{project_id}/lts/alarms/keywords-alarm-rule { "keywords_alarm_rule_id" : "", "keywords_alarm_rule_name" : "huawei", "alarm_rule_alias" : "zhangsan", "keywords_alarm_rule_description" : "huawei", "keywords_requests" : [ { "log_stream_id" : "1", "log_group_id" : "1", "keywords" : "huawei", "condition" : ">", "number" : "100", "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" }, "keywords_alarm_level" : "Critical", "keywords_alarm_send" : true, "keywords_alarm_send_code" : "2", "domain_id" : "", "notification_frequency" : 5, "alarm_action_rule_name" : "", "notification_save_rule" : { "language" : "zh-cn", "timezone" : "Asia/Shanghai", "user_name" : "huawei", "template_name" : "Message template name.", "topics" : [ { "name" : "huawei", "topic_urn" : "urn:smn:cn-north-7:1b06fc5dc0814a4da1594a9ade9cb93c:huawei", "display_name" : "", "push_policy" : 0 } ] } }
Example Responses
Status code: 200
The request is successful.
{ "keywords_alarm_rule_id" : "", "keywords_alarm_rule_name" : "huawei", "keywords_alarm_rule_description" : "huawei", "alarm_rule_alias" : "zhangsan", "keywords_requests" : [ { "log_stream_id" : "1", "log_stream_name" : "huawei", "log_group_name" : "huawei", "log_group_id" : "1", "keywords" : "huawei", "condition" : ">", "number" : "100", "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" }, "keywords_alarm_level" : "Critical", "keywords_alarm_send" : false, "domain_id" : "", "notification_frequency" : 5, "alarm_action_rule_name" : "", "topics" : [ { "name" : "huawei", "topic_urn" : "urn:smn:cn-north-7:1b06fc5dc0814a4da1594a9ade9cb93c:huawei", "display_name" : "", "push_policy" : 0 } ], "language" : "zh-cn" }
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.
Modifying a keyword 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
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 UpdateKeywordsAlarmRuleSolution { 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(); UpdateKeywordsAlarmRuleRequest request = new UpdateKeywordsAlarmRuleRequest(); UpdateKeywordsAlarmRuleRequestBody body = new UpdateKeywordsAlarmRuleRequestBody(); List<Topics> listNotificationSaveRuleTopics = new ArrayList<>(); listNotificationSaveRuleTopics.add( new Topics() .withName("huawei") .withTopicUrn("urn:smn:cn-north-7:1b06fc5dc0814a4da1594a9ade9cb93c:huawei") .withDisplayName("") .withPushPolicy(0) ); SqlNotificationSaveRule notificationSaveRulebody = new SqlNotificationSaveRule(); notificationSaveRulebody.withLanguage(SqlNotificationSaveRule.LanguageEnum.fromValue("zh-cn")) .withTimezone("Asia/Shanghai") .withUserName("huawei") .withTopics(listNotificationSaveRuleTopics) .withTemplateName("Message template name."); Frequency frequencybody = new Frequency(); frequencybody.withType(Frequency.TypeEnum.fromValue("FIXED_RATE")) .withCronExpr("") .withHourOfDay(0) .withDayOfWeek(0) .withFixedRate(10) .withFixedRateUnit(Frequency.FixedRateUnitEnum.fromValue("minute")); List<KeywordsRequest> listbodyKeywordsRequests = new ArrayList<>(); listbodyKeywordsRequests.add( new KeywordsRequest() .withLogStreamId("1") .withLogGroupId("1") .withKeywords("huawei") .withCondition(KeywordsRequest.ConditionEnum.fromValue(">")) .withNumber(100) .withSearchTimeRange(10) .withSearchTimeRangeUnit(KeywordsRequest.SearchTimeRangeUnitEnum.fromValue("minute")) ); body.withAlarmActionRuleName(""); body.withNotificationFrequency(UpdateKeywordsAlarmRuleRequestBody.NotificationFrequencyEnum.NUMBER_5); body.withNotificationSaveRule(notificationSaveRulebody); body.withDomainId(""); body.withKeywordsAlarmSendCode(UpdateKeywordsAlarmRuleRequestBody.KeywordsAlarmSendCodeEnum.NUMBER_2); body.withKeywordsAlarmSend(true); body.withKeywordsAlarmLevel(UpdateKeywordsAlarmRuleRequestBody.KeywordsAlarmLevelEnum.fromValue("Critical")); body.withFrequency(frequencybody); body.withKeywordsRequests(listbodyKeywordsRequests); body.withKeywordsAlarmRuleDescription("huawei"); body.withAlarmRuleAlias("zhangsan"); body.withKeywordsAlarmRuleName("huawei"); body.withKeywordsAlarmRuleId(""); request.withBody(body); try { UpdateKeywordsAlarmRuleResponse response = client.updateKeywordsAlarmRule(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()); } } } |
Modifying a keyword 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 80 |
# 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 = UpdateKeywordsAlarmRuleRequest() listTopicsNotificationSaveRule = [ Topics( name="huawei", topic_urn="urn:smn:cn-north-7:1b06fc5dc0814a4da1594a9ade9cb93c:huawei", display_name="", push_policy=0 ) ] notificationSaveRulebody = SqlNotificationSaveRule( language="zh-cn", timezone="Asia/Shanghai", user_name="huawei", topics=listTopicsNotificationSaveRule, template_name="Message template name." ) frequencybody = Frequency( type="FIXED_RATE", cron_expr="", hour_of_day=0, day_of_week=0, fixed_rate=10, fixed_rate_unit="minute" ) listKeywordsRequestsbody = [ KeywordsRequest( log_stream_id="1", log_group_id="1", keywords="huawei", condition=">", number=100, search_time_range=10, search_time_range_unit="minute" ) ] request.body = UpdateKeywordsAlarmRuleRequestBody( alarm_action_rule_name="", notification_frequency=5, notification_save_rule=notificationSaveRulebody, domain_id="", keywords_alarm_send_code=2, keywords_alarm_send=True, keywords_alarm_level="Critical", frequency=frequencybody, keywords_requests=listKeywordsRequestsbody, keywords_alarm_rule_description="huawei", alarm_rule_alias="zhangsan", keywords_alarm_rule_name="huawei", keywords_alarm_rule_id="" ) response = client.update_keywords_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) |
Modifying a keyword 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
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.UpdateKeywordsAlarmRuleRequest{} displayNameTopics:= "" pushPolicyTopics:= int32(0) var listTopicsNotificationSaveRule = []model.Topics{ { Name: "huawei", TopicUrn: "urn:smn:cn-north-7:1b06fc5dc0814a4da1594a9ade9cb93c:huawei", DisplayName: &displayNameTopics, PushPolicy: &pushPolicyTopics, }, } timezoneNotificationSaveRule:= "Asia/Shanghai" notificationSaveRulebody := &model.SqlNotificationSaveRule{ Language: model.GetSqlNotificationSaveRuleLanguageEnum().ZH_CN, Timezone: &timezoneNotificationSaveRule, UserName: "huawei", Topics: listTopicsNotificationSaveRule, TemplateName: "Message template name.", } cronExprFrequency:= "" hourOfDayFrequency:= int32(0) dayOfWeekFrequency:= int32(0) fixedRateFrequency:= int32(10) fixedRateUnitFrequency:= model.GetFrequencyFixedRateUnitEnum().MINUTE frequencybody := &model.Frequency{ Type: model.GetFrequencyTypeEnum().FIXED_RATE, CronExpr: &cronExprFrequency, HourOfDay: &hourOfDayFrequency, DayOfWeek: &dayOfWeekFrequency, FixedRate: &fixedRateFrequency, FixedRateUnit: &fixedRateUnitFrequency, } var listKeywordsRequestsbody = []model.KeywordsRequest{ { LogStreamId: "1", LogGroupId: "1", Keywords: "huawei", Condition: model.GetKeywordsRequestConditionEnum().GREATER_THAN, Number: int32(100), SearchTimeRange: int32(10), SearchTimeRangeUnit: model.GetKeywordsRequestSearchTimeRangeUnitEnum().MINUTE, }, } alarmActionRuleNameUpdateKeywordsAlarmRuleRequestBody:= "" keywordsAlarmRuleDescriptionUpdateKeywordsAlarmRuleRequestBody:= "huawei" alarmRuleAliasUpdateKeywordsAlarmRuleRequestBody:= "zhangsan" request.Body = &model.UpdateKeywordsAlarmRuleRequestBody{ AlarmActionRuleName: &alarmActionRuleNameUpdateKeywordsAlarmRuleRequestBody, NotificationFrequency: model.GetUpdateKeywordsAlarmRuleRequestBodyNotificationFrequencyEnum().E_5, NotificationSaveRule: notificationSaveRulebody, DomainId: "", KeywordsAlarmSendCode: model.GetUpdateKeywordsAlarmRuleRequestBodyKeywordsAlarmSendCodeEnum().E_2, KeywordsAlarmSend: true, KeywordsAlarmLevel: model.GetUpdateKeywordsAlarmRuleRequestBodyKeywordsAlarmLevelEnum().CRITICAL, Frequency: frequencybody, KeywordsRequests: listKeywordsRequestsbody, KeywordsAlarmRuleDescription: &keywordsAlarmRuleDescriptionUpdateKeywordsAlarmRuleRequestBody, AlarmRuleAlias: &alarmRuleAliasUpdateKeywordsAlarmRuleRequestBody, KeywordsAlarmRuleName: "huawei", KeywordsAlarmRuleId: "", } response, err := client.UpdateKeywordsAlarmRule(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