创建结构化配置(不推荐)
功能介绍
该接口用于创建指定日志流下的结构化配置。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/lts/struct/template
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
Content-Type |
是 |
String |
该字段填为:application/json;charset=utf8。 |
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token,获取方式请参见:获取用户Token |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
log_group_id |
是 |
String |
日志组ID 缺省值:None |
log_stream_id |
是 |
String |
日志流ID 缺省值:None |
project_id |
是 |
String |
项目ID 缺省值:None |
content |
是 |
String |
填写一条示例日志。 |
demo_fields |
是 |
Array of DemoFields objects |
示例字段列表。
说明:
demo_fields中的字段顺序,须和content中的字段顺序保持一致。 最大个数:200 |
parse_type |
是 |
String |
结构化类型参数(json、split、nginx、built_in、custom_regex)。 |
regex_rules |
否 |
String |
正则表达式(使用正则结构化规则时候需要)。 |
layers |
否 |
Integer |
最大解析层数(使用JSON方式结构化需要)。 |
tokenizer |
否 |
String |
分隔符(使用分隔符结构化时需要)。 |
log_format |
否 |
String |
Nginx配置规则(使用分隔符结构化时需要)。 |
tag_fields |
是 |
Array of TagField objects |
tag字段列表(使用tag字段解析时需要,其中系统模板不支持使用tag字段)。 最大个数:200 |
rule |
否 |
StructRule object |
结构化方式 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
fieldName |
否 |
String |
字段名称 缺省值:None |
userDefinedName |
否 |
String |
自定义别名(json,Nginx方式中按需添加) 缺省值:None |
type |
是 |
String |
字段数据类型。 可选范围:string、long、float |
isAnalysis |
否 |
Boolean |
预留字段。 |
content |
否 |
String |
字段内容。
说明:
在系统模板中,此参数为demoLog。 |
index |
否 |
Integer |
序号 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
- |
String |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
调用失败响应信息描述。 |
状态码: 401
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
调用失败响应信息描述。 |
状态码: 403
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
调用失败响应信息描述。 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
调用失败响应信息描述。 |
请求示例
-
VPC:
{ "content" : "1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK", "demo_fields" : [ { "fieldName" : "version", "content" : 1, "type" : "long", "isAnalysis" : true }, { "fieldName" : "project_id", "content" : "5f67944957444bd6bb4fe3b367de8f3d", "type" : "string", "isAnalysis" : true }, { "fieldName" : "interface_id", "content" : "1d515d18-1b36-47dc-a983-bd6512aed4bd", "type" : "string", "isAnalysis" : true }, { "fieldName" : "srcaddr", "content" : "192.168.0.154", "type" : "string", "isAnalysis" : true }, { "fieldName" : "dstaddr", "content" : "192.168.3.25", "type" : "string", "isAnalysis" : true }, { "fieldName" : "srcport", "content" : "38929", "type" : "long", "isAnalysis" : true }, { "fieldName" : "dstport", "content" : "53", "type" : "long", "isAnalysis" : true }, { "fieldName" : "protocol", "content" : "17", "type" : "long", "isAnalysis" : true }, { "fieldName" : "packets", "content" : "1", "type" : "long", "isAnalysis" : true }, { "fieldName" : "bytes", "content" : "96", "type" : "long", "isAnalysis" : true }, { "fieldName" : "start", "content" : "1548752136", "type" : "long", "isAnalysis" : true }, { "fieldName" : "end", "content" : "1548752736", "type" : "long", "isAnalysis" : true }, { "fieldName" : "action", "content" : "ACCEPT", "type" : "string", "isAnalysis" : true }, { "fieldName" : "log_status", "content" : "OK", "type" : "string", "isAnalysis" : true } ], "rule" : { "type" : "built_in", "param" : "VPC" }, "tag_fields" : [ { "fieldName" : "hostIP", "content" : "192.168.2.134", "type" : "string", "isAnalysis" : true }, { "fieldName" : "hostName", "content" : "ecs-ictest", "type" : "string", "isAnalysis" : true } ], "log_group_id" : "925a750-e0f3-4fe9-a046-a04af676xxxx", "log_stream_id" : "7e432db8-9dad-4723-a4b1-fdabf712xxxx", "parse_type" : " ", "project_id" : "2a473356cca5487f8373be891bffxxxx" }
-
ELB:
{ "content" : "1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 \"GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1\" 233 293 138 0.001 \"200\" \"0.000\" \"0.001\" \"0.001\" \"100.0.0.0:9999\" \"lua-resty-http/0.14 (Lua) ngx_lua/10000\" \"-\" \"-\" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b \"-\" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 \"101.0.0.0:10000\" - - - - 9739", "demo_fields" : [ { "fieldName" : "msec", "content" : "1594727856.337", "type" : "float", "isAnalysis" : true }, { "fieldName" : "access_log_topic_id", "content" : "e7c37d97-e922-457c-bbf3-dsadeqac", "type" : "string", "isAnalysis" : true }, { "fieldName" : "time_iso8601", "content" : "2020-07-14T19:57:36+08:00", "type" : "string", "isAnalysis" : true }, { "fieldName" : "log_ver", "content" : "elb_01", "type" : "string", "isAnalysis" : true }, { "fieldName" : "remote_addr", "content" : "192.0.0.0", "type" : "string", "isAnalysis" : true }, { "fieldName" : "remote_port", "content" : "88888", "type" : "long", "isAnalysis" : true }, { "fieldName" : "status", "content" : "200", "type" : "long", "isAnalysis" : true }, { "fieldName" : "request_method", "content" : "GET", "type" : "string", "isAnalysis" : true }, { "fieldName" : "scheme", "content" : "http", "type" : "string", "isAnalysis" : true }, { "fieldName" : "host", "content" : "prod.sss.ads.sg2.aaa", "type" : "string", "isAnalysis" : true }, { "fieldName" : "router_request_uri", "content" : "loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada", "type" : "string", "isAnalysis" : true }, { "fieldName" : "server_protocol", "content" : "HTTP/1.1", "type" : "string", "isAnalysis" : true }, { "fieldName" : "request_length", "content" : "233", "type" : "long", "isAnalysis" : true }, { "fieldName" : "bytes_sent", "content" : "293", "type" : "long", "isAnalysis" : true }, { "fieldName" : "body_bytes_sent", "content" : "138", "type" : "long", "isAnalysis" : true }, { "fieldName" : "request_time", "content" : "0.001", "type" : "float", "isAnalysis" : true }, { "fieldName" : "upstream_status", "content" : "200", "type" : "long", "isAnalysis" : true }, { "fieldName" : "upstream_connect_time", "content" : "0.000", "type" : "float", "isAnalysis" : true }, { "fieldName" : "upstream_header_time", "content" : "0.001", "type" : "float", "isAnalysis" : true }, { "fieldName" : "upstream_response_time", "content" : "0.001", "type" : "float", "isAnalysis" : true }, { "fieldName" : "upstream_addr", "content" : "100.0.0.0:9999", "type" : "string", "isAnalysis" : true }, { "fieldName" : "http_user_agent", "content" : "lua-resty-http/0.14 (Lua) ngx_lua/10000", "type" : "string", "isAnalysis" : true }, { "fieldName" : "http_referer", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "http_x_forwarded_for", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "lb_name", "content" : "loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa", "type" : "string", "isAnalysis" : true }, { "fieldName" : "listener_name", "content" : "listener_6077809b-913f-466d-a96c-376f08882d5d", "type" : "string", "isAnalysis" : true }, { "fieldName" : "listener_id", "content" : "08cc2b3f68aa4dddd1e6a90dddd1688348a4480", "type" : "string", "isAnalysis" : true }, { "fieldName" : "pool_name", "content" : "pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b", "type" : "string", "isAnalysis" : true }, { "fieldName" : "member_name", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "tenant_id", "content" : "2fb78dsadadq1213das1121dab146ad3cb0", "type" : "string", "isAnalysis" : true }, { "fieldName" : "eip_address", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "eip_port", "content" : "80", "type" : "long", "isAnalysis" : true }, { "fieldName" : "upstream_addr_priv", "content" : "101.0.0.0:10000", "type" : "string", "isAnalysis" : true }, { "fieldName" : "certificate_id", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "ssl_protocol", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "ssl_cipher", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "sni_domain_name", "content" : "-", "type" : "string", "isAnalysis" : true }, { "fieldName" : "tcpinfo_rtt", "content" : "9739", "type" : "long", "isAnalysis" : true } ], "rule" : { "type" : "built_in", "param" : "ELB" }, "tag_fields" : [ { "fieldName" : "hostIP", "content" : "192.168.2.134", "type" : "string", "isAnalysis" : true }, { "fieldName" : "hostName", "content" : "ecs-ictest", "type" : "string", "isAnalysis" : true } ], "log_group_id" : "925a750-e0f3-4fe9-a046-a04af676xxxx", "log_stream_id" : "7e432db8-9dad-4723-a4b1-fdabf712xxxx", "parse_type" : " ", "project_id" : "2a473356cca5487f8373be891bffxxxx" }
响应示例
状态码: 200
请求响应成功, 成功创建结构化配置。
{ "2a473356cca5487f8373be891bffc1cf_8a75b77d-7d72-4d7e-8c50-a24562cf8b0b_fd5e1a7c-7412-475d-a013-8891d539574e" }
状态码: 400
BadRequest。非法请求。 建议根据error_msg直接修改该请求,不要重试该请求。
{ "errorCode" : "LTS.0612", "errorMessage" : "timee fieldType is error" }
状态码: 401
AuthFailed。鉴权失败, 请确认token后再次请求 。
{ "error_code" : "LTS.0414", "error_msg" : "Invalid token" }
状态码: 403
Forbidden。
请求被拒绝访问。
返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。
{ "error_code" : "LTS.0001", "error_msg" : "Invalid projectId" }
SDK代码示例
SDK代码示例如下。
-
VPC:
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
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 CreateStructTemplateSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); CreateStructTemplateRequest request = new CreateStructTemplateRequest(); LtsStructTemplateInfo body = new LtsStructTemplateInfo(); Rule rulebody = new Rule(); rulebody.withType("built_in") .withParam("VPC"); List<TagField> listbodyTagFields = new ArrayList<>(); listbodyTagFields.add( new TagField() .withFieldName("hostIP") .withType("string") .withContent("192.168.2.134") .withIsAnalysis(true) ); listbodyTagFields.add( new TagField() .withFieldName("hostName") .withType("string") .withContent("ecs-ictest") .withIsAnalysis(true) ); List<StructFieldInfo> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1") .withFieldName("version") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("5f67944957444bd6bb4fe3b367de8f3d") .withFieldName("project_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1d515d18-1b36-47dc-a983-bd6512aed4bd") .withFieldName("interface_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("192.168.0.154") .withFieldName("srcaddr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("192.168.3.25") .withFieldName("dstaddr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("38929") .withFieldName("srcport") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("53") .withFieldName("dstport") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("17") .withFieldName("protocol") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1") .withFieldName("packets") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("96") .withFieldName("bytes") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1548752136") .withFieldName("start") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1548752736") .withFieldName("end") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("ACCEPT") .withFieldName("action") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("OK") .withFieldName("log_status") .withType("string") ); body.withRule(rulebody); body.withProjectId("2a473356cca5487f8373be891bffxxxx"); body.withLogStreamId("7e432db8-9dad-4723-a4b1-fdabf712xxxx"); body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" ")); body.withLogGroupId("925a750-e0f3-4fe9-a046-a04af676xxxx"); body.withContent("1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK"); body.withTagFields(listbodyTagFields); body.withDemoFields(listbodyDemoFields); request.withBody(body); try { CreateStructTemplateResponse response = client.createStructTemplate(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()); } } }
-
ELB:
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
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 CreateStructTemplateSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); LtsClient client = LtsClient.newBuilder() .withCredential(auth) .withRegion(LtsRegion.valueOf("<YOUR REGION>")) .build(); CreateStructTemplateRequest request = new CreateStructTemplateRequest(); LtsStructTemplateInfo body = new LtsStructTemplateInfo(); Rule rulebody = new Rule(); rulebody.withType("built_in") .withParam("ELB"); List<TagField> listbodyTagFields = new ArrayList<>(); listbodyTagFields.add( new TagField() .withFieldName("hostIP") .withType("string") .withContent("192.168.2.134") .withIsAnalysis(true) ); listbodyTagFields.add( new TagField() .withFieldName("hostName") .withType("string") .withContent("ecs-ictest") .withIsAnalysis(true) ); List<StructFieldInfo> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("1594727856.337") .withFieldName("msec") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("e7c37d97-e922-457c-bbf3-dsadeqac") .withFieldName("access_log_topic_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("2020-07-14T19:57:36+08:00") .withFieldName("time_iso8601") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("elb_01") .withFieldName("log_ver") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("192.0.0.0") .withFieldName("remote_addr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("88888") .withFieldName("remote_port") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("200") .withFieldName("status") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("GET") .withFieldName("request_method") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("http") .withFieldName("scheme") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("prod.sss.ads.sg2.aaa") .withFieldName("host") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada") .withFieldName("router_request_uri") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("HTTP/1.1") .withFieldName("server_protocol") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("233") .withFieldName("request_length") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("293") .withFieldName("bytes_sent") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("138") .withFieldName("body_bytes_sent") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("0.001") .withFieldName("request_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("200") .withFieldName("upstream_status") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("0.000") .withFieldName("upstream_connect_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("0.001") .withFieldName("upstream_header_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("0.001") .withFieldName("upstream_response_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("100.0.0.0:9999") .withFieldName("upstream_addr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("lua-resty-http/0.14 (Lua) ngx_lua/10000") .withFieldName("http_user_agent") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("http_referer") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("http_x_forwarded_for") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa") .withFieldName("lb_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("listener_6077809b-913f-466d-a96c-376f08882d5d") .withFieldName("listener_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("08cc2b3f68aa4dddd1e6a90dddd1688348a4480") .withFieldName("listener_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b") .withFieldName("pool_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("member_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("2fb78dsadadq1213das1121dab146ad3cb0") .withFieldName("tenant_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("eip_address") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("80") .withFieldName("eip_port") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("101.0.0.0:10000") .withFieldName("upstream_addr_priv") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("certificate_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("ssl_protocol") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("ssl_cipher") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("-") .withFieldName("sni_domain_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withIsAnalysis(true) .withContent("9739") .withFieldName("tcpinfo_rtt") .withType("long") ); body.withRule(rulebody); body.withProjectId("2a473356cca5487f8373be891bffxxxx"); body.withLogStreamId("7e432db8-9dad-4723-a4b1-fdabf712xxxx"); body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" ")); body.withLogGroupId("925a750-e0f3-4fe9-a046-a04af676xxxx"); body.withContent("1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739"); body.withTagFields(listbodyTagFields); body.withDemoFields(listbodyDemoFields); request.withBody(body); try { CreateStructTemplateResponse response = client.createStructTemplate(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()); } } }
-
VPC:
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 133 134 135 136 137 138 139 140 141 142 143 144 145
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdklts.v2.region.lts_region import LtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdklts.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateStructTemplateRequest() rulebody = Rule( type="built_in", param="VPC" ) listTagFieldsbody = [ TagField( field_name="hostIP", type="string", content="192.168.2.134", is_analysis=True ), TagField( field_name="hostName", type="string", content="ecs-ictest", is_analysis=True ) ] listDemoFieldsbody = [ StructFieldInfo( is_analysis=True, content="1", field_name="version", type="long" ), StructFieldInfo( is_analysis=True, content="5f67944957444bd6bb4fe3b367de8f3d", field_name="project_id", type="string" ), StructFieldInfo( is_analysis=True, content="1d515d18-1b36-47dc-a983-bd6512aed4bd", field_name="interface_id", type="string" ), StructFieldInfo( is_analysis=True, content="192.168.0.154", field_name="srcaddr", type="string" ), StructFieldInfo( is_analysis=True, content="192.168.3.25", field_name="dstaddr", type="string" ), StructFieldInfo( is_analysis=True, content="38929", field_name="srcport", type="long" ), StructFieldInfo( is_analysis=True, content="53", field_name="dstport", type="long" ), StructFieldInfo( is_analysis=True, content="17", field_name="protocol", type="long" ), StructFieldInfo( is_analysis=True, content="1", field_name="packets", type="long" ), StructFieldInfo( is_analysis=True, content="96", field_name="bytes", type="long" ), StructFieldInfo( is_analysis=True, content="1548752136", field_name="start", type="long" ), StructFieldInfo( is_analysis=True, content="1548752736", field_name="end", type="long" ), StructFieldInfo( is_analysis=True, content="ACCEPT", field_name="action", type="string" ), StructFieldInfo( is_analysis=True, content="OK", field_name="log_status", type="string" ) ] request.body = LtsStructTemplateInfo( rule=rulebody, project_id="2a473356cca5487f8373be891bffxxxx", log_stream_id="7e432db8-9dad-4723-a4b1-fdabf712xxxx", parse_type=" ", log_group_id="925a750-e0f3-4fe9-a046-a04af676xxxx", content="1 5f67944957444bd6bb4fe3b367de8f3d 1d515d18-1b36-47dc-a983-bd6512aed4bd 192.168.0.154 192.168.3.25 38929 53 17 1 96 1548752136 1548752736 ACCEPT OK", tag_fields=listTagFieldsbody, demo_fields=listDemoFieldsbody ) response = client.create_struct_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)
-
ELB:
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdklts.v2.region.lts_region import LtsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdklts.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = LtsClient.new_builder() \ .with_credentials(credentials) \ .with_region(LtsRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateStructTemplateRequest() rulebody = Rule( type="built_in", param="ELB" ) listTagFieldsbody = [ TagField( field_name="hostIP", type="string", content="192.168.2.134", is_analysis=True ), TagField( field_name="hostName", type="string", content="ecs-ictest", is_analysis=True ) ] listDemoFieldsbody = [ StructFieldInfo( is_analysis=True, content="1594727856.337", field_name="msec", type="float" ), StructFieldInfo( is_analysis=True, content="e7c37d97-e922-457c-bbf3-dsadeqac", field_name="access_log_topic_id", type="string" ), StructFieldInfo( is_analysis=True, content="2020-07-14T19:57:36+08:00", field_name="time_iso8601", type="string" ), StructFieldInfo( is_analysis=True, content="elb_01", field_name="log_ver", type="string" ), StructFieldInfo( is_analysis=True, content="192.0.0.0", field_name="remote_addr", type="string" ), StructFieldInfo( is_analysis=True, content="88888", field_name="remote_port", type="long" ), StructFieldInfo( is_analysis=True, content="200", field_name="status", type="long" ), StructFieldInfo( is_analysis=True, content="GET", field_name="request_method", type="string" ), StructFieldInfo( is_analysis=True, content="http", field_name="scheme", type="string" ), StructFieldInfo( is_analysis=True, content="prod.sss.ads.sg2.aaa", field_name="host", type="string" ), StructFieldInfo( is_analysis=True, content="loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada", field_name="router_request_uri", type="string" ), StructFieldInfo( is_analysis=True, content="HTTP/1.1", field_name="server_protocol", type="string" ), StructFieldInfo( is_analysis=True, content="233", field_name="request_length", type="long" ), StructFieldInfo( is_analysis=True, content="293", field_name="bytes_sent", type="long" ), StructFieldInfo( is_analysis=True, content="138", field_name="body_bytes_sent", type="long" ), StructFieldInfo( is_analysis=True, content="0.001", field_name="request_time", type="float" ), StructFieldInfo( is_analysis=True, content="200", field_name="upstream_status", type="long" ), StructFieldInfo( is_analysis=True, content="0.000", field_name="upstream_connect_time", type="float" ), StructFieldInfo( is_analysis=True, content="0.001", field_name="upstream_header_time", type="float" ), StructFieldInfo( is_analysis=True, content="0.001", field_name="upstream_response_time", type="float" ), StructFieldInfo( is_analysis=True, content="100.0.0.0:9999", field_name="upstream_addr", type="string" ), StructFieldInfo( is_analysis=True, content="lua-resty-http/0.14 (Lua) ngx_lua/10000", field_name="http_user_agent", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="http_referer", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="http_x_forwarded_for", type="string" ), StructFieldInfo( is_analysis=True, content="loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa", field_name="lb_name", type="string" ), StructFieldInfo( is_analysis=True, content="listener_6077809b-913f-466d-a96c-376f08882d5d", field_name="listener_name", type="string" ), StructFieldInfo( is_analysis=True, content="08cc2b3f68aa4dddd1e6a90dddd1688348a4480", field_name="listener_id", type="string" ), StructFieldInfo( is_analysis=True, content="pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b", field_name="pool_name", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="member_name", type="string" ), StructFieldInfo( is_analysis=True, content="2fb78dsadadq1213das1121dab146ad3cb0", field_name="tenant_id", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="eip_address", type="string" ), StructFieldInfo( is_analysis=True, content="80", field_name="eip_port", type="long" ), StructFieldInfo( is_analysis=True, content="101.0.0.0:10000", field_name="upstream_addr_priv", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="certificate_id", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="ssl_protocol", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="ssl_cipher", type="string" ), StructFieldInfo( is_analysis=True, content="-", field_name="sni_domain_name", type="string" ), StructFieldInfo( is_analysis=True, content="9739", field_name="tcpinfo_rtt", type="long" ) ] request.body = LtsStructTemplateInfo( rule=rulebody, project_id="2a473356cca5487f8373be891bffxxxx", log_stream_id="7e432db8-9dad-4723-a4b1-fdabf712xxxx", parse_type=" ", log_group_id="925a750-e0f3-4fe9-a046-a04af676xxxx", content="1594727856.337 e7c37d97-e922-457c-bbf3-dsadeqac 2020-07-14T19:57:36+08:00 elb_01 192.0.0.0:88888 200 "GET http://prod.sss.ads.sg2.aaa/loc/ation?version=3&ip=100.0.0.0&coordinate=27.7044784,85.3007481&device_id=dsadsadasdsadasd&beyla_id=wqeb123ndadsa233ddada HTTP/1.1" 233 293 138 0.001 "200" "0.000" "0.001" "0.001" "100.0.0.0:9999" "lua-resty-http/0.14 (Lua) ngx_lua/10000" "-" "-" loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa listener_6077809b-913f-466d-a96c-376f08882d5d 08cc2b3f68aa4dddd1e6a90dddd1688348a4480 pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b "-" 2fb78dsadadq1213das1121dab146ad3cb0 -:80 "101.0.0.0:10000" - - - - 9739", tag_fields=listTagFieldsbody, demo_fields=listDemoFieldsbody ) response = client.create_struct_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)
-
VPC:
-
ELB:
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求响应成功, 成功创建结构化配置。 |
400 |
BadRequest。非法请求。 建议根据error_msg直接修改该请求,不要重试该请求。 |
401 |
AuthFailed。鉴权失败, 请确认token后再次请求 。 |
403 |
Forbidden。 请求被拒绝访问。 返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。 |
500 |
InternalServerError。 表明服务端能被请求访问到,但是服务内部出错。 |
503 |
ServiceUnavailable。 被请求的服务无效,服务不可用。 |
错误码
请参见错误码。