
# 修改消息模板 - UpdateNotificationTemplate
#### 功能介绍
该接口用于修改消息模板,根据名称进行修改。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-lts/lts_api_0003.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-lts/lts_api_0046.html)。
- 如果使用身份策略授权，需具备如下身份策略权限。
  
  | 授权项                            | 访问级别  | 资源类型（\*为必须） | 条件键 | 别名                    | 依赖的授权项 |
  |:---|:---|:---|:---|:---|:---|
  | lts:alarmNoticeTemplate:update | Write | -           | -   | lts:sqlalarmrules:put | -      |
     
  
 
#### URI
PUT /v2/{project_id}/{domain_id}/lts/events/notification/templates
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                      |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，可以从调用API处获取，也可以从控制台获取。获取方式请参见：[获取项目ID](https://support.huaweicloud.com/api-lts/lts_api_0006.html)。 |
| domain_id  | 是    | String | 账号ID，获取方式请参见：[获取账号ID](https://support.huaweicloud.com/api-lts/lts_api_0012.html)                        |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | **参数解释：** 从IAM服务获取的用户Token，获取方式请参见：[获取用户Token](https://support.huaweicloud.com/api-lts/lts_api_0004.html)。 **约束限制：** 不涉及。 **取值范围：** 不涉及。 **默认取值：** 不涉及。 |
| Content-Type | 是    | String | **参数解释：** 用于定义消息体的格式，该字段填为：application/json;charset=utf8。 **约束限制：** 不涉及。 **取值范围：** 不涉及。 **默认取值：** 不涉及。                                                  |
   
表3请求Body参数 
| 参数        | 是否必选 | 参数类型                                                                                         | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|:---|:---|:---|:---|
| name      | 是    | String                                                                                       | 通知规则名称，必填，只含有汉字、数字、字母、下划线、中划线，不能以下划线等特殊符号开头和结尾，长度为 1 - 100，创建后不可修改                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| type      | 否    | Array of strings                                                                             | **参数解释：** 保留字段，非必填。 **约束限制：** 不涉及。 **取值范围：** - sms   - dingding   - wechat   - webhook   - email    |
| desc      | 否    | String                                                                                       | 模板描述，非必填，只含有汉字、数字、字母、下划线不能以下划线开头和结尾，长度为0--1024                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| source    | 是    | String                                                                                       | 模板来源，目前必填为LTS，否则会筛选不出来                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| locale    | 是    | String                                                                                       | 语言，必填，目前可填zh-cn和en-us                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| templates | 是    | Array of [UpdateSubTemplate] objects | 模板正文，为一个数组                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
   
 表4UpdateSubTemplate 
| 参数       | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
|:---|:---|:---|:---|
| sub_type | 是    | String | **参数解释：** 模板子类型。 **约束限制：** 不涉及。 **取值范围：** - sms   - dingding   - wechat   - webhook   - email   - voice                                                                                                                                                                                                                                                                                              |
| content  | 是    | String | 子模板正文，$符号后所跟变量仅支持以下变量，根据不同告警类型（关键词告警和sql告警），所支持的变量亦不相同。目前两种告警类型有共同变量如下： 告警级别：${event_severity}; 发生时间：${starts_at}; 告警源：$event.metadata.resource_provider; 资源类型：$event.metadata.resource_type; 资源标识：${resources}; 统计类型：关键词统计; 表达式：$event.annotations.condition_expression; 当前值: $event.annotations.current_value; 统计周期：$event.annotations.frequency; 关键词告警特有变量： 查询时间：$event.annotations.results\[0\].time; 查询日志：$event.annotations.results\[0\].raw_results; sql告警特有变量： 日志组/流名称：$event.annotations.results\[0\].resource_id; 查询语句：$event.annotations.results\[0\].sql; 查询时间：$event.annotations.results\[0\].time; 查询URL：$event.annotations.results\[0\].url; 查询日志：$event.annotations.results\[0\].raw_results; 说明： 变量后面的分号";"为英文符号，必须添加，否则模板会出现替换失败的情况。 |
| topic    | 否    | String | 邮件主题,只有sub_type=email时生效                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
   
#### 响应参数
**状态码：201**
表5响应Body参数 
| 参数        | 参数类型                                                                                            | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|
| name      | String                                                                                          | **参数解释：** 消息模板名称。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| type      | Array of strings                                                                                | **参数解释：** 消息通知方式。 **取值范围：** - sms   - dingding   - wechat   - webhook   - email   - voice   - feishu   - welink    |
| desc      | String                                                                                          | **参数解释：** 消息模板描述。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| source    | String                                                                                          | **参数解释：** 消息模板来源。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| templates | Array of [SubTemplateResBody] objects | **参数解释：** 不同通知渠道下消息模板的详细信息。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| locale    | String                                                                                          | **参数解释：** 消息头语言，系统在发送消息时会默认添加消息头，中文如："尊敬的用户..."；英文如："Dear User..."。 **取值范围：** - zh-cn   - en-us                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
   
 表6SubTemplateResBody 
| 参数       | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| sub_type | String | **参数解释：** 消息模板的通知渠道。 **取值范围：** - sms   - dingding   - wechat   - webhook   - email   - voice   - feishu   - welink                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| content  | String | **参数解释：** 对应通知渠道的消息模板正文，$符号后所跟变量仅支持以下变量，根据不同告警类型（关键词告警和sql告警），所支持的变量亦不相同。目前两种告警类型有共同变量如下： 告警级别：${event_severity}; 发生时间：${starts_at}; 告警源：$event.metadata.resource_provider; 资源类型：$event.metadata.resource_type; 资源标识：${resources}; 统计类型：关键词统计; 表达式：$event.annotations.condition_expression; 当前值: $event.annotations.current_value; 统计周期：$event.annotations.frequency; 关键词告警特有变量： 查询时间：$event.annotations.results\[0\].time; 查询日志：$event.annotations.results\[0\].raw_results; sql告警特有变量： 日志组/流名称：$event.annotations.results\[0\].resource_id; 查询语句：$event.annotations.results\[0\].sql; 查询时间：$event.annotations.results\[0\].time; 查询URL：$event.annotations.results\[0\].url; 查询日志：$event.annotations.results\[0\].raw_results; 告警级别：${event_severity}; 发生时间：${starts_at}; 告警源：$event.metadata.resource_provider; 资源类型：$event.metadata.resource_type; 资源标识：${resources}; 统计类型：关键词统计; 表达式：$event.annotations.condition_expression; 当前值: $event.annotations.current_value; 统计周期：$event.annotations.frequency; 告警详情：$event.annotations.alarm_rule_desc; 关键词告警特有变量： 查询时间：$event.annotations.results\[0\].time; 查询日志：$event.annotations.results\[0\].raw_results; sql告警特有变量： 日志组/流名称：$event.annotations.results\[0\].resource_id; 查询语句：$event.annotations.results\[0\].sql; 查询时间：$event.annotations.results\[0\].time; 查询URL：$event.annotations.results\[0\].url; 查询日志：$event.annotations.results\[0\].raw_results; 说明： 变量后面的分号";"为英文符号，必须添加，否则模板会出现替换失败的情况。 **取值范围：** 不涉及。 |
| topic    | String | **参数解释：** 邮件主题。通知渠道为邮件时生效，即sub_type=email。 **取值范围：** 不涉及。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| sendType | String | **参数解释：** 当消息模板类型为webhook时生效，决定该消息的渲染方式。 **取值范围：** - HTML   - JSON                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| version  | String | **参数解释：** 消息模板的适用版本。 **取值范围：** v1：标识为LTS的消息模板。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
   
**状态码：400**
表7响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                                                                                                        |
|:---|:---|:---|
| error_code | String | **参数解释：** 错误码，请参见：[错误码](https://support.huaweicloud.com/api-lts/ErrorCode.html)。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 调用失败响应信息描述。 **取值范围：** 不涉及。                                                            |
   
**状态码：500**
表8响应Body参数 
| 参数         | 参数类型   | 描述                                                                                                                                                                                                                                        |
|:---|:---|:---|
| error_code | String | **参数解释：** 错误码，请参见：[错误码](https://support.huaweicloud.com/api-lts/ErrorCode.html)。 **取值范围：** 不涉及。 |
| error_msg  | String | **参数解释：** 调用失败响应信息描述。 **取值范围：** 不涉及。                                                            |
   
#### 请求示例
修改消息模板
```
PUT 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" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;"
  }, {
    "sub_type" : "dingding",
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;"
  }, {
    "sub_type" : "wechat",
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;"
  }, {
    "sub_type" : "webhook",
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;"
  }, {
    "sub_type" : "email",
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n告警源：$event.metadata.resource_provider;\n资源类型：$event.metadata.resource_type;\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;\n查询时间：$event.annotations.results[0].time;\n查询日志：$event.annotations.results[0].raw_results;"
  }, {
    "sub_type" : "voice",
    "content" : "告警级别：${event_severity};  \n发生时间：${starts_at};  \n资源标识：${resources};  \n统计类型：关键词统计;  \n表达式：$event.annotations.condition_expression;  \n当前值: $event.annotations.current_value;  \n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;"
  } ]
}
```
#### 响应示例
**状态码：201**
请求响应成功。
```
{
  "desc" : "description",
  "locale" : "zh-cn",
  "name" : "postman-test1",
  "source" : "LTS",
  "templates" : [ {
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;",
    "sub_type" : "sms"
  }, {
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;",
    "sub_type" : "dingding"
  }, {
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;",
    "sub_type" : "wechat"
  }, {
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;",
    "sub_type" : "webhook"
  }, {
    "content" : "告警级别：${event_severity};\n发生时间：${starts_at};\n告警源：$event.metadata.resource_provider;\n资源类型：$event.metadata.resource_type;\n资源标识：${resources};\n统计类型：关键词统计;\n表达式：$event.annotations.condition_expression;\n当前值: $event.annotations.current_value;\n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;\n查询时间：$event.annotations.results[0].time;\n查询日志：$event.annotations.results[0].raw_results;",
    "sub_type" : "email"
  }, {
    "content" : "告警级别：${event_severity};  \n发生时间：${starts_at};  \n资源标识：${resources};  \n统计类型：关键词统计;  \n表达式：$event.annotations.condition_expression;  \n当前值: $event.annotations.current_value;  \n统计周期：$event.annotations.frequency;\n告警描述：$event.annotations.alarm_rule_desc;",
    "sub_type" : "voice"
  } ],
  "type" : [ ]
}
```
**状态码：400**
非法请求。
```
{
  "error_code" : "LTS.2016",
  "error_msg" : "desc is invalid!"
}
```
**状态码：500**
表明服务端能被请求访问到，但是服务内部出错。
```
{
  "error_code" : "LTS.2016",
  "error_msg" : "Failed to update notification template"
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  修改消息模板
  ```
  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 UpdateNotificationTemplateSolution {
      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();
          UpdateNotificationTemplateRequest request = new UpdateNotificationTemplateRequest();
          request.withDomainId("{domain_id}");
          UpdateNotificationTemplateRequestBody body = new UpdateNotificationTemplateRequestBody();
          List<UpdateSubTemplate> listbodyTemplates = new ArrayList<>();
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("sms"))
                  .withContent("告警级别:${event_severity};
  发生时间:${starts_at};
  资源标识:${resources};
  统计类型:关键词统计;
  表达式:$event.annotations.condition_expression;
  当前值: $event.annotations.current_value;
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;")
          );
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("dingding"))
                  .withContent("告警级别:${event_severity};
  发生时间:${starts_at};
  资源标识:${resources};
  统计类型:关键词统计;
  表达式:$event.annotations.condition_expression;
  当前值: $event.annotations.current_value;
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;")
          );
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("wechat"))
                  .withContent("告警级别:${event_severity};
  发生时间:${starts_at};
  资源标识:${resources};
  统计类型:关键词统计;
  表达式:$event.annotations.condition_expression;
  当前值: $event.annotations.current_value;
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;")
          );
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("webhook"))
                  .withContent("告警级别:${event_severity};
  发生时间:${starts_at};
  资源标识:${resources};
  统计类型:关键词统计;
  表达式:$event.annotations.condition_expression;
  当前值: $event.annotations.current_value;
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;")
          );
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("email"))
                  .withContent("告警级别:${event_severity};
  发生时间:${starts_at};
  告警源:$event.metadata.resource_provider;
  资源类型:$event.metadata.resource_type;
  资源标识:${resources};
  统计类型:关键词统计;
  表达式:$event.annotations.condition_expression;
  当前值: $event.annotations.current_value;
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;
  查询时间:$event.annotations.results[0].time;
  查询日志:$event.annotations.results[0].raw_results;")
          );
          listbodyTemplates.add(
              new UpdateSubTemplate()
                  .withSubType(UpdateSubTemplate.SubTypeEnum.fromValue("voice"))
                  .withContent("告警级别:${event_severity};  
  发生时间:${starts_at};  
  资源标识:${resources};  
  统计类型:关键词统计;  
  表达式:$event.annotations.condition_expression;  
  当前值: $event.annotations.current_value;  
  统计周期:$event.annotations.frequency;
  告警描述:$event.annotations.alarm_rule_desc;")
          );
          body.withTemplates(listbodyTemplates);
          body.withLocale(UpdateNotificationTemplateRequestBody.UpdateNotificationTemplateRequestBody.fromValue("zh-cn"));
          body.withSource("LTS");
          body.withDesc("xxxxxx");
          body.withName("xxx");
          request.withBody(body);
          try {
              UpdateNotificationTemplateResponse response = client.updateNotificationTemplate(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());
          }
      }
  }
  ```
- [Python]
  修改消息模板
  ```
  # 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 = UpdateNotificationTemplateRequest()
          request.domain_id = "{domain_id}"
          listTemplatesbody = [
              UpdateSubTemplate(
                  sub_type="sms",
                  content="告警级别:${event_severity};
          发生时间:${starts_at};
          资源标识:${resources};
          统计类型:关键词统计;
          表达式:$event.annotations.condition_expression;
          当前值: $event.annotations.current_value;
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;"
              ),
              UpdateSubTemplate(
                  sub_type="dingding",
                  content="告警级别:${event_severity};
          发生时间:${starts_at};
          资源标识:${resources};
          统计类型:关键词统计;
          表达式:$event.annotations.condition_expression;
          当前值: $event.annotations.current_value;
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;"
              ),
              UpdateSubTemplate(
                  sub_type="wechat",
                  content="告警级别:${event_severity};
          发生时间:${starts_at};
          资源标识:${resources};
          统计类型:关键词统计;
          表达式:$event.annotations.condition_expression;
          当前值: $event.annotations.current_value;
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;"
              ),
              UpdateSubTemplate(
                  sub_type="webhook",
                  content="告警级别:${event_severity};
          发生时间:${starts_at};
          资源标识:${resources};
          统计类型:关键词统计;
          表达式:$event.annotations.condition_expression;
          当前值: $event.annotations.current_value;
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;"
              ),
              UpdateSubTemplate(
                  sub_type="email",
                  content="告警级别:${event_severity};
          发生时间:${starts_at};
          告警源:$event.metadata.resource_provider;
          资源类型:$event.metadata.resource_type;
          资源标识:${resources};
          统计类型:关键词统计;
          表达式:$event.annotations.condition_expression;
          当前值: $event.annotations.current_value;
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;
          查询时间:$event.annotations.results[0].time;
          查询日志:$event.annotations.results[0].raw_results;"
              ),
              UpdateSubTemplate(
                  sub_type="voice",
                  content="告警级别:${event_severity};  
          发生时间:${starts_at};  
          资源标识:${resources};  
          统计类型:关键词统计;  
          表达式:$event.annotations.condition_expression;  
          当前值: $event.annotations.current_value;  
          统计周期:$event.annotations.frequency;
          告警描述:$event.annotations.alarm_rule_desc;"
              )
          ]
          request.body = UpdateNotificationTemplateRequestBody(
              templates=listTemplatesbody,
              locale="zh-cn",
              source="LTS",
              desc="xxxxxx",
              name="xxx"
          )
          response = client.update_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)
  ```
- [Go]
  修改消息模板
  ```
  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, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := lts.LtsClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := lts.NewLtsClient(hcClient)
      request := &model.UpdateNotificationTemplateRequest{}
  request.DomainId = "{domain_id}"
  var listTemplatesbody = []model.UpdateSubTemplate{
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().SMS,
              Content: "告警级别:${event_severity};
      发生时间:${starts_at};
      资源标识:${resources};
      统计类型:关键词统计;
      表达式:$event.annotations.condition_expression;
      当前值: $event.annotations.current_value;
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;",
          },
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().DINGDING,
              Content: "告警级别:${event_severity};
      发生时间:${starts_at};
      资源标识:${resources};
      统计类型:关键词统计;
      表达式:$event.annotations.condition_expression;
      当前值: $event.annotations.current_value;
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;",
          },
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().WECHAT,
              Content: "告警级别:${event_severity};
      发生时间:${starts_at};
      资源标识:${resources};
      统计类型:关键词统计;
      表达式:$event.annotations.condition_expression;
      当前值: $event.annotations.current_value;
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;",
          },
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().WEBHOOK,
              Content: "告警级别:${event_severity};
      发生时间:${starts_at};
      资源标识:${resources};
      统计类型:关键词统计;
      表达式:$event.annotations.condition_expression;
      当前值: $event.annotations.current_value;
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;",
          },
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().EMAIL,
              Content: "告警级别:${event_severity};
      发生时间:${starts_at};
      告警源:$event.metadata.resource_provider;
      资源类型:$event.metadata.resource_type;
      资源标识:${resources};
      统计类型:关键词统计;
      表达式:$event.annotations.condition_expression;
      当前值: $event.annotations.current_value;
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;
      查询时间:$event.annotations.results[0].time;
      查询日志:$event.annotations.results[0].raw_results;",
          },
          {
              SubType: model.GetUpdateSubTemplateSubTypeEnum().VOICE,
              Content: "告警级别:${event_severity};  
      发生时间:${starts_at};  
      资源标识:${resources};  
      统计类型:关键词统计;  
      表达式:$event.annotations.condition_expression;  
      当前值: $event.annotations.current_value;  
      统计周期:$event.annotations.frequency;
      告警描述:$event.annotations.alarm_rule_desc;",
          },
      }
  descUpdateNotificationTemplateRequestBody:= "xxxxxx"
  request.Body = &model.UpdateNotificationTemplateRequestBody{
  Templates: listTemplatesbody,
  Locale: model.GetUpdateNotificationTemplateRequestBodyLocaleEnum().ZH_CN,
  Source: "LTS",
  Desc: &descUpdateNotificationTemplateRequestBody,
  Name: "xxx",
  }
  response, err := client.UpdateNotificationTemplate(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/LTS/sdk?api=UpdateNotificationTemplate)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                     |
|:---|:---|
| 201 | 请求响应成功。                |
| 400 | 非法请求。                  |
| 500 | 表明服务端能被请求访问到，但是服务内部出错。 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-lts/ErrorCode.html)。
