Creating a Message Template
Function
This API is used to create a notification template. Currently, each account can create a maximum of 100 notification templates. After a notification template is created, its name cannot be changed.
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:alarmNoticeTemplate:create
Write
-
-
- lts:sqlalarmrules:create
-
URI
POST /v2/{project_id}/{domain_id}/lts/events/notification/templates
|
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 |
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 |
|---|---|---|---|
|
name |
Yes |
String |
Notification rule name, which is mandatory. The value can contain only digits, letters, underscores (), and hyphens (-), and cannot start or end with special characters such as underscores (). The value can contain 1 to 100 characters and cannot be changed after being created. Minimum: 1 Maximum: 100 |
|
type |
No |
Array of strings |
This field is reserved and optional. |
|
desc |
No |
String |
Template description, which is optional. Enter a maximum of 1,024 characters, including only digits, letters, and underscores (). Do not start or end with an underscore (). Minimum: 0 Maximum: 1024 |
|
source |
Yes |
String |
Template source. Currently, this parameter must be set to LTS. Otherwise, the template cannot be filtered. Minimum: 3 Maximum: 3 |
|
locale |
Yes |
String |
Language, which is mandatory. The value can be zh-cn or en-us. Enumeration values:
|
|
templates |
Yes |
Array of SubTemplate objects |
Template body is an array. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
sub_type |
Yes |
String |
Template subtype. Only the following types are supported: sms, dingding (DingTalk), wechat (WeCom), webhook, and email. Enumeration values:
|
|
content |
Yes |
String |
In the sub-template body, the variables following the dollar sign ($) can only be the following variables. The supported variables vary according to alarm rule types (keyword or SQL). Currently, the two alarm rule types have the following common variables: Severity: ${event_severity}; Occurred: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Variables specific to keyword alarms: Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results; Variables specific to SQL alarms: Log group/stream name: $event.annotations.results[0].resource_id; Query statement: $event.annotations.results[0].sql; Query time: $event.annotations.results[0].time; Query URL: $event.annotations.results[0].url; Query log: $event.annotations.results[0].raw_results;
NOTE:
Each variable must be followed by an English semicolon (;). Otherwise, the template replacement fails.
Minimum: 2 Maximum: 1024 |
|
topic |
No |
String |
Email subject. This parameter is valid only when sub_type is set to email. |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
name |
String |
Definition Message template name. Range N/A |
|
type |
Array of strings |
Definition Notification method. Range
|
|
desc |
String |
Definition Message template description. Range N/A |
|
source |
String |
Definition Message template source. Range N/A |
|
templates |
Array of SubTemplateResBody objects |
Definition Details about the message template of different notification channels. |
|
locale |
String |
Definition Message header language. A default header, such as "Dear customer," will be added to the beginning of all messages in the language you select. Range
|
|
Parameter |
Type |
Description |
|---|---|---|
|
sub_type |
String |
Definition Notification channel of the message template. Range
|
|
content |
String |
Definition Message template body of the corresponding notification channel. A variable following a dollar sign ($) can only be one of the following variables. The supported variables vary according to alarm rule types (keyword or SQL). Currently, the two alarm rule types have the following common variables: Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Variables specific to keyword alarms: Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results; Variables specific to SQL alarms: Log group/stream name: $event.annotations.results[0].resource_id; Query statement: $event.annotations.results[0].sql; Query time: $event.annotations.results[0].time; Query URL: $event.annotations.results[0].url; Query log: $event.annotations.results[0].raw_results; Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm details: $event.annotations.alarm_rule_desc; Variables specific to keyword alarms: Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results; Variables specific to SQL alarms: Log group/stream name: $event.annotations.results[0].resource_id; Query statement: $event.annotations.results[0].sql; Query time: $event.annotations.results[0].time; Query URL: $event.annotations.results[0].url; Query log: $event.annotations.results[0].raw_results;
NOTE:
Each variable must be followed by an English semicolon (;). Otherwise, the template replacement fails.
Range N/A |
|
topic |
String |
Definition Email subject. This field is valid when sub_type (notification channel) is set to email. Range N/A |
|
sendType |
String |
Definition Rendering mode of the message. This field is valid only when the message template type is webhook. Range
|
|
version |
String |
Definition Applicable version of the message template. Range v1: indicates the LTS message template. |
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
Creating a message template
POST https://{endpoint}/v2/{project_id}/{domain_id}/lts/events/notification/templates
{
"name" : "xxx",
"desc" : "xxxxxx",
"type" : [ ],
"source" : "LTS",
"locale" : "zh-cn",
"templates" : [ {
"sub_type" : "sms",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;"
}, {
"sub_type" : "dingding",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;"
}, {
"sub_type" : "wechat",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;"
}, {
"sub_type" : "webhook",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;"
}, {
"sub_type" : "email",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nAlarm source: $event.metadata.resource_provider;\nResource type: $event.metadata.resource_type;\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;\nQuery time: $event.annotations.results[0].time;\nQuery log: $event.annotations.results[0].raw_results;"
}, {
"sub_type" : "voice",
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;"
} ]
}
Example Responses
Status code: 200
The request is successful.
{
"desc" : "description",
"locale" : "zh-cn",
"name" : "postman-test",
"source" : "LTS",
"templates" : [ {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;",
"sub_type" : "sms"
}, {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;",
"sub_type" : "dingding"
}, {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;",
"sub_type" : "wechat"
}, {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;",
"sub_type" : "webhook"
}, {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nAlarm source: $event.metadata.resource_provider;\nResource type: $event.metadata.resource_type;\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;\nQuery time: $event.annotations.results[0].time;\nQuery log: $event.annotations.results[0].raw_results;",
"sub_type" : "email"
}, {
"content" : "Alarm severity: ${event_severity};\nOccurrence time: ${starts_at};\nResource ID: ${resources};\nStatistical type: by keyword;\nExpression: $event.annotations.condition_expression;\nCurrent value: $event.annotations.current_value;\nStatistical period: $event.annotations.frequency;\nAlarm description: $event.annotations.alarm_rule_desc;",
"sub_type" : "voice"
} ],
"type" : [ ]
}
Status code: 400
Invalid request. Modify the request based on the description in error_msg before a retry.
{
"error_code" : "LTS.2014",
"error_msg" : "desc is invalid!"
}
Status code: 500
The server has received the request but encountered an internal error.
{
"error_code" : "LTS.2014",
"error_msg" : "Failed to create notification template."
}
SDK Sample Code
The SDK sample code is as follows.
Creating a message template
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
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 CreateNotificationTemplateSolution { 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"); ICredential auth = new BasicCredentials() .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); CreateNotificationTemplateRequest request = new CreateNotificationTemplateRequest(); request.withDomainId("{domain_id}"); CreateNotificationTemplateRequestBody body = new CreateNotificationTemplateRequestBody(); List<SubTemplate> listbodyTemplates = new ArrayList<>(); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("sms")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;") ); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("dingding")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;") ); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("wechat")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;") ); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("webhook")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;") ); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("email")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc; Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results;") ); listbodyTemplates.add( new SubTemplate() .withSubType(SubTemplate.SubTypeEnum.fromValue("voice")) .withContent("Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;") ); body.withTemplates(listbodyTemplates); body.withLocale(CreateNotificationTemplateRequestBody.LocaleEnum.fromValue("zh-cn")); body.withSource("LTS"); body.withDesc("xxxxxx"); body.withName("xxx"); request.withBody(body); try { CreateNotificationTemplateResponse response = client.createNotificationTemplate(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()); } } } |
Creating a message template
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 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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"] credentials = BasicCredentials(ak, sk) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateNotificationTemplateRequest() request.domain_id = "{domain_id}" listTemplatesbody = [ SubTemplate( sub_type="sms", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;" ), SubTemplate( sub_type="dingding", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;" ), SubTemplate( sub_type="wechat", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;" ), SubTemplate( sub_type="webhook", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;" ), SubTemplate( sub_type="email", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc; Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results;" ), SubTemplate( sub_type="voice", content="Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;" ) ] request.body = CreateNotificationTemplateRequestBody( templates=listTemplatesbody, locale="zh-cn", source="LTS", desc="xxxxxx", name="xxx" ) response = client.create_notification_template(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Creating a message template
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateNotificationTemplateRequest{} request.DomainId = "{domain_id}" var listTemplatesbody = []model.SubTemplate{ { SubType: model.GetSubTemplateSubTypeEnum().SMS, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;", }, { SubType: model.GetSubTemplateSubTypeEnum().DINGDING, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;", }, { SubType: model.GetSubTemplateSubTypeEnum().WECHAT, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;", }, { SubType: model.GetSubTemplateSubTypeEnum().WEBHOOK, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;", }, { SubType: model.GetSubTemplateSubTypeEnum().EMAIL, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Alarm source: $event.metadata.resource_provider; Resource type: $event.metadata.resource_type; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc; Query time: $event.annotations.results[0].time; Query log: $event.annotations.results[0].raw_results;", }, { SubType: model.GetSubTemplateSubTypeEnum().VOICE, Content: "Alarm severity: ${event_severity}; Occurrence time: ${starts_at}; Resource ID: ${resources}; Statistical type: by keyword; Expression: $event.annotations.condition_expression; Current value: $event.annotations.current_value; Statistical period: $event.annotations.frequency; Alarm description: $event.annotations.alarm_rule_desc;", }, } descCreateNotificationTemplateRequestBody:= "xxxxxx" request.Body = &model.CreateNotificationTemplateRequestBody{ Templates: listTemplatesbody, Locale: model.GetCreateNotificationTemplateRequestBodyLocaleEnum().ZH_CN, Source: "LTS", Desc: &descCreateNotificationTemplateRequestBody, Name: "xxx", } response, err := client.CreateNotificationTemplate(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