更新时间:2025-08-20 GMT+08:00

查询单个消息模板

功能介绍

查询单个消息通知模板。通过该接口可查询单个消息通知模板的信息,包括模板名称、内容、创建时间等,为您开展模板管理提供精准数据支撑。

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/{domain_id}/lts/events/notification/template/{template_name}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,可以从调用API处获取,也可以从控制台获取。获取方式请参见:获取项目ID

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

domain_id

String

参数解释:

账号ID,获取方式请参见:获取账号ID

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

template_name

String

参数解释:

待获取的消息模板名称。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

从IAM服务获取的用户Token,获取方式请参见:获取用户Token

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

Content-Type

String

参数解释:

用于定义消息体的格式,该字段填为:application/json;charset=utf8。

约束限制:

不涉及。

取值范围:

不涉及。

默认取值:

不涉及。

响应参数

状态码:200

表3 响应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

create_time

Long

参数解释:

消息模板的创建时间(单位为毫秒时间戳)。

取值范围:

不涉及。

modify_time

Long

参数解释:

消息模板最后一次的更新时间(单位为毫秒时间戳)。

取值范围:

不涉及。

project_id

String

参数解释:

项目ID。

取值范围:

不涉及。

表4 SubTemplateResBody

参数

参数类型

描述

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.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的消息模板。

状态码:500

表5 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码,请参见:错误码

取值范围:

不涉及。

error_msg

String

参数解释:

调用失败响应信息描述。

取值范围:

不涉及。

请求示例

查询指定名称的消息模板。

GET https://{endpoint}/v2/{project_id}/{domain_id}/lts/events/notification/template/{template_name}

/v2/{project_id}/{domain_id}/lts/events/notification/template/{template_name}

响应示例

状态码:200

请求响应成功。

{
  "create_time" : 1702955600631,
  "desc" : "description",
  "locale" : "zh-cn",
  "modify_time" : 1702955600631,
  "name" : "postman-test",
  "project_id" : "2a473356cca5487f8373be891bffc1cf",
  "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;",
    "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;",
    "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;",
    "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;",
    "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.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;",
    "sub_type" : "voice"
  } ],
  "type" : [ ]
}

状态码:500

表明服务端能被请求访问到,但是服务内部出错。

{
  "error_code" : "LTS.2018",
  "error_msg" : "Failed to get notification template."
}

状态码

状态码

描述

200

请求响应成功。

500

表明服务端能被请求访问到,但是服务内部出错。

错误码

请参见错误码