查询结构化模板
功能介绍
该接口用于查询自定义结构化模板。
URI
GET /v3/{project_id}/lts/struct/customtemplate
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| project_id | 是 | String | 项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID 最小长度:32 最大长度:32 |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| id | 否 | String | 待查询模板id,非必填,不传时返回项目下所有自定义结构化模板。从查询自定义结构化模板的接口中获取。 最小长度:36 最大长度:36 |
请求参数
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| X-Auth-Token | 是 | String | 从IAM服务获取的用户Token,获取方式请参见:获取用户Token 最小长度:1000 最大长度:2000 |
| Content-Type | 是 | String | 该字段填为:application/json;charset=UTF-8。 最小长度:30 最大长度:30 |
响应参数
状态码:200
| 参数 | 参数类型 | 描述 |
|---|---|---|
| results | Array of StructTemplateModel objects | 查询的自定义结构化模板数组 |
| 参数 | 参数类型 | 描述 |
|---|---|---|
| project_id | String | 项目id |
| template_name | String | 模板名称 |
| template_type | String | 模板类型,regex,json,split,nginx |
| demo_log | String | 示例日志 |
| demo_fields | Array of DemoField objects | 示例字段数组 |
| tag_fields | Array of TagFieldNew objects | Tag字段数组 |
| rule | TemplateRule object | 结构化规则对象 |
| demo_label | String | 示例日志标签 |
| create_time | Long | 创建时间 |
| id | String | 模板id |
| 参数 | 参数类型 | 描述 |
|---|---|---|
| field_name | String | 字段名称 |
| content | String | 字段示例内容,字段的示例值 |
| type | String | 字段数据类型。 可选范围:string、long、float |
| is_analysis | Boolean | 是否开启快速分析 |
| index | Integer | 手动正则及分隔符方式中字段序号 |
| relation | String | 描叙多层级json中字段间的层级关系 |
| user_defined_name | String | json及nginx方式中字段自定义别名 |
| 参数 | 参数类型 | 描述 |
|---|---|---|
| field_name | String | 字段名称 |
| content | String | 字段示例内容,字段的示例值 |
| type | String | 字段数据类型。 可选范围:string、long、float |
| is_analysis | Boolean | 是否开启快速分析 |
| index | Integer | 序号,从0开始 |
| 参数 | 参数类型 | 描述 |
|---|---|---|
| type | String | 结构化类型,只支持正则结构化、JSON结构化、分隔符结构化、NGINX结构化,分别对应的参数值为regex、json、split、nginx。 |
| param | String | 具体结构化规则,每种结构化类型都有自己独有的结构,具体结构如下: 手动正则为json字符串,包含keyObject对象和regex_rules对象,keyObject内为键值对,键为demo_fields数组中元素的index,值为field_name,regex_rules对象为正则表达式字符串,整体例子为 {\"keyObject\":{\"1\":\"date\",\"2\":\"num\"},\"regex_rules\":\"^(?<date>[^/]+)(?:[^]* ){8}(?<num>\\\\d+)\"} json方式时param为一个json字符串,包含keyObject对象和layers对象,keyObject内为键值对,键为demo_fields数组中元素的field_name,值为user_defined_name,layers为最大解析层数,当前最大值为4,整体例子为 {\"keyObject\":{\"metadata.dimension\":\"dimension\",\"metadata.value\":\"\",\"metadata.unit\":\"\",\"collectionTime\":\"\"},\"layers\":3} 分隔符方式时为json字符串,包含keyObject对象和tokenizer对象,keyObject内为键值对,键为demo_fields数组中元素的index,值为field_name,tokenizer对象为所用分隔符,整体例子为 {\"keyObject\":{\"0\":\"field1\",\"1\":\"field2\",\"2\":\"field3\",\"3\":\"field4\",\"4\":\"field5\",\"5\":\"field6\",\"6\":\"field7\",\"7\":\"field8\",\"8\":\"field9\"},\"tokenizer\":\"\"} nginx方式时为json字符串,包含keyObject对象,regex对象,field_names对象及log_format对象,keyObject内为键值对,键为demo_fields数组中元素的field_name,值为user_defined_name,regex为正则表达式字符串,field_names对象为demo_fields数组中各元素的field_name的拼接字符串,每个field_name以','分隔,log_format对象为nginx日志格式化方式,整体例子为 {\"keyObject\": { \"http_host\": \"host\", \"remote_addr\": \"\", \"request_method\": \"\", \"request_uri\": \"\", \"time_local\": \"\" }, \"regex\": \"(\\\\d+/\\\\S+/\\\\d+:\\\\d+:\\\\d+:\\\\d+)\\\\s+\\\\S+\\\\s+(\\\\S*)\\\\s+(\\\\S*)\\\\s+(\\\\S*)\\\\s+\\\"([^\\\"]*)\\\".*\", \"fieldNames\": \"time_local,remote_addr,request_method,http_host,request_uri\", \"log_format\": \"log_format '$upstreaminfo '$time_local $remote_addr $request_method $http_host\\\"$request_uri\\\"';\" } |
状态码:400
| 参数 | 参数类型 | 描述 |
|---|---|---|
| message | CustomTemplateErrorCode object | 请求的报错内容 |
状态码:500
| 参数 | 参数类型 | 描述 |
|---|---|---|
| error_code | String | 错误码。 |
| error_msg | String | 调用失败响应信息描述。 |
请求示例
查询当前结构化模板详情
GET https://{endpoint}/v3/{project_id}/lts/struct/customtemplate?id=bc8e3f2c-87fe-4acd-8439-69cdf29251c1
/v3/{project_id}/lts/struct/customtemplate?id=bc8e3f2c-87fe-4acd-8439-69cdf29251c1 响应示例
状态码:200
请求响应成功。
{
"results" : [ {
"create_time" : 1641258099551,
"demo_fields" : [ {
"content" : "2022-01-03/14:52:28",
"field_name" : "field1",
"index" : 0,
"is_analysis" : true,
"type" : "string"
}, {
"content" : "this",
"field_name" : "field2",
"index" : 1,
"is_analysis" : true,
"type" : "string"
}, {
"content" : "log",
"field_name" : "field3",
"index" : 2,
"is_analysis" : false,
"type" : "string"
}, {
"content" : "is",
"field_name" : "field4",
"index" : 3,
"is_analysis" : false,
"type" : "string"
}, {
"content" : "Error",
"field_name" : "field5",
"index" : 4,
"is_analysis" : false,
"type" : "string"
}, {
"content" : "NO",
"field_name" : "field6",
"index" : 5,
"is_analysis" : false,
"type" : "string"
}, {
"content" : "13测试",
"field_name" : "field7",
"index" : 6,
"is_analysis" : false,
"type" : "string"
}, {
"content" : "286",
"field_name" : "field8",
"index" : 7,
"is_analysis" : false,
"type" : "long"
} ],
"demo_log" : "2022-01-03/14:52:28 this log is Error NO 13测试 286",
"id" : "43a8cc7b-b632-4c36-a65d-8150e98219f1",
"project_id" : "2a473356cca5487f8373be89xxxxxxxx",
"rule" : {
"param" : "{\"keyObject\":{\"0\":\"field1\",\"1\":\"field2\",\"2\":\"field3\",\"3\":\"field4\",\"4\":\"field5\",\"5\":\"field6\",\"6\":\"field7\",\"7\":\"field8\"},\"tokenizer\":\" \"}",
"type" : "split"
},
"demo_label" : "here is a demo label",
"tag_fields" : [ {
"content" : "172.16.10.69",
"field_name" : "hostIP",
"index" : 0,
"is_analysis" : true,
"type" : "string"
} ],
"template_name" : "testSplit13",
"template_type" : "split"
} ]
} 状态码:400
id不存在
{
"message" : {
"code" : "LTS.0751",
"details" : "custom template doesn't exist"
}
} 状态码:500
表明服务端能被请求访问到,但是服务内部出错。
{
"error_code" : "LTS.2017",
"error_msg" : "Find struct template failed."
} 状态码
| 状态码 | 描述 |
|---|---|
| 200 | 请求响应成功。 |
| 400 | id不存在 |
| 500 | 表明服务端能被请求访问到,但是服务内部出错。 |
错误码
请参见错误码。