修改结构化配置(不推荐)
功能介绍
该接口用于修改指定日志流下的结构化配置,由于参数较多且构建复杂,建议您使用8.9.2-修改结构化配置(推荐)。
调用方法
请参见如何调用API。
URI
PUT /v2/{project_id}/lts/struct/template
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token,获取方式请参见:获取用户Token |
Content-Type |
是 |
String |
该字段填为:application/json;charset=UTF-8。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
log_group_id |
是 |
String |
日志组ID 最小长度:36 最大长度:36 |
log_stream_id |
是 |
String |
日志流ID 最小长度:36 最大长度:36 |
project_id |
是 |
String |
项目ID 最小长度:32 最大长度:32 |
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 |
正则表达式(使用正则结构化规则时候需要)。 最大长度:5000 |
layers |
否 |
Integer |
最大解析层数(使用JSON方式结构化需要)。 最大值:3 |
tokenizer |
否 |
String |
分隔符(使用分隔符结构化时需要)。 |
log_format |
否 |
String |
Nginx配置规则(使用分隔符结构化时需要)。 |
tag_fields |
是 |
Array of TagField objects |
tag字段列表(使用tag字段解析时需要,其中系统模板不支持使用tag字段)。 最大个数:200 |
rule |
否 |
StructRule object |
结构化方式 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
fieldName |
否 |
String |
字段名称 最小长度:1 最大长度:50 |
userDefinedName |
否 |
String |
自定义别名(json,Nginx方式中按需添加) 最小长度:1 最大长度:64 |
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 |
调用失败响应信息描述。 |
状态码: 503
参数 |
参数类型 |
描述 |
---|---|---|
- |
String |
请求示例
-
修改VPC方式的结构化配置。
PUT https://{endpoint}/v2/{project_id}/lts/struct/template { "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" }, { "fieldName" : "project_id", "content" : "5f67944957444bd6bb4fe3b367de8f3d", "type" : "string" }, { "fieldName" : "interface_id", "content" : "1d515d18-1b36-47dc-a983-bd6512aed4bd", "type" : "string" }, { "fieldName" : "srcaddr", "content" : "192.168.0.154", "type" : "string" }, { "fieldName" : "dstaddr", "content" : "192.168.3.25", "type" : "string" }, { "fieldName" : "srcport", "content" : "38929", "type" : "long" }, { "fieldName" : "dstport", "content" : "53", "type" : "long" }, { "fieldName" : "protocol", "content" : "17", "type" : "long" }, { "fieldName" : "packets", "content" : "1", "type" : "long" }, { "fieldName" : "bytes", "content" : "96", "type" : "long" }, { "fieldName" : "start", "content" : "1548752136", "type" : "long" }, { "fieldName" : "end", "content" : "1548752736", "type" : "long" }, { "fieldName" : "action", "content" : "ACCEPT", "type" : "string" }, { "fieldName" : "log_status", "content" : "OK", "type" : "string" } ], "rule" : { "type" : "built_in", "param" : "VPC" }, "log_group_id" : " ", "log_stream_id" : " ", "project_id" : " ", "parse_type" : " ", "tag_fields" : [ { "fieldName" : "hostIP", "content" : "192.168.2.134", "type" : "string", "isAnalysis" : true } ] }
-
修改ELB方式的结构化配置。
PUT https://{endpoint}/v2/{project_id}/lts/struct/template { "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" }, { "fieldName" : "access_log_topic_id", "content" : "e7c37d97-e922-457c-bbf3-dsadeqac", "type" : "string" }, { "fieldName" : "time_iso8601", "content" : "2020-07-14T19:57:36+08:00", "type" : "string" }, { "fieldName" : "log_ver", "content" : "elb_01", "type" : "string" }, { "fieldName" : "remote_addr", "content" : "192.0.0.0", "type" : "string" }, { "fieldName" : "remote_port", "content" : "88888", "type" : "long" }, { "fieldName" : "status", "content" : "200", "type" : "long" }, { "fieldName" : "request_method", "content" : "GET", "type" : "string" }, { "fieldName" : "scheme", "content" : "http", "type" : "string" }, { "fieldName" : "host", "content" : "prod.sss.ads.sg2.aaa", "type" : "string" }, { "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" }, { "fieldName" : "server_protocol", "content" : "HTTP/1.1", "type" : "string" }, { "fieldName" : "request_length", "content" : "233", "type" : "long" }, { "fieldName" : "bytes_sent", "content" : "293", "type" : "long" }, { "fieldName" : "body_bytes_sent", "content" : "138", "type" : "long" }, { "fieldName" : "request_time", "content" : "0.001", "type" : "float" }, { "fieldName" : "upstream_status", "content" : "200", "type" : "long" }, { "fieldName" : "upstream_connect_time", "content" : "0.000", "type" : "float" }, { "fieldName" : "upstream_header_time", "content" : "0.001", "type" : "float" }, { "fieldName" : "upstream_response_time", "content" : "0.001", "type" : "float" }, { "fieldName" : "upstream_addr", "content" : "100.0.0.0:9999", "type" : "string" }, { "fieldName" : "http_user_agent", "content" : "lua-resty-http/0.14 (Lua) ngx_lua/10000", "type" : "string" }, { "fieldName" : "http_referer", "content" : "-", "type" : "string" }, { "fieldName" : "http_x_forwarded_for", "content" : "-", "type" : "string" }, { "fieldName" : "lb_name", "content" : "loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa", "type" : "string" }, { "fieldName" : "listener_name", "content" : "listener_6077809b-913f-466d-a96c-376f08882d5d", "type" : "string" }, { "fieldName" : "listener_id", "content" : "08cc2b3f68aa4dddd1e6a90dddd1688348a4480", "type" : "string" }, { "fieldName" : "pool_name", "content" : "pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b", "type" : "string" }, { "fieldName" : "member_name", "content" : "-", "type" : "string" }, { "fieldName" : "tenant_id", "content" : "2fb78dsadadq1213das1121dab146ad3cb0", "type" : "string" }, { "fieldName" : "eip_address", "content" : "-", "type" : "string" }, { "fieldName" : "eip_port", "content" : "80", "type" : "long" }, { "fieldName" : "upstream_addr_priv", "content" : "101.0.0.0:10000", "type" : "string" }, { "fieldName" : "certificate_id", "content" : "-", "type" : "string" }, { "fieldName" : "ssl_protocol", "content" : "-", "type" : "string" }, { "fieldName" : "ssl_cipher", "content" : "-", "type" : "string" }, { "fieldName" : "sni_domain_name", "content" : "-", "type" : "string" }, { "fieldName" : "tcpinfo_rtt", "content" : "9739", "type" : "long" } ], "rule" : { "type" : "built_in", "param" : "ELB" }, "tag_fields" : [ { "fieldName" : "hostIP", "content" : "192.168.2.134", "type" : "string", "isAnalysis" : true } ], "log_group_id" : " ", "log_stream_id" : " ", "project_id" : " ", "parse_type" : " " }
响应示例
状态码: 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" }
状态码: 500
InternalServerError。
表明服务端能被请求访问到,但是服务内部出错。
{ "error_code" : "LTS.0102", "error_msg" : "Failed to create log group" }
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
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 UpdateStructTemplateSolution { 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(); UpdateStructTemplateRequest request = new UpdateStructTemplateRequest(); 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) ); List<StructFieldInfo> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new StructFieldInfo() .withContent("1") .withFieldName("version") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("5f67944957444bd6bb4fe3b367de8f3d") .withFieldName("project_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("1d515d18-1b36-47dc-a983-bd6512aed4bd") .withFieldName("interface_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("192.168.0.154") .withFieldName("srcaddr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("192.168.3.25") .withFieldName("dstaddr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("38929") .withFieldName("srcport") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("53") .withFieldName("dstport") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("17") .withFieldName("protocol") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("1") .withFieldName("packets") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("96") .withFieldName("bytes") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("1548752136") .withFieldName("start") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("1548752736") .withFieldName("end") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("ACCEPT") .withFieldName("action") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("OK") .withFieldName("log_status") .withType("string") ); body.withRule(rulebody); body.withProjectId(" "); body.withLogStreamId(" "); body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" ")); body.withLogGroupId(" "); 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 { UpdateStructTemplateResponse response = client.updateStructTemplate(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
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 UpdateStructTemplateSolution { 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(); UpdateStructTemplateRequest request = new UpdateStructTemplateRequest(); 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) ); List<StructFieldInfo> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new StructFieldInfo() .withContent("1594727856.337") .withFieldName("msec") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("e7c37d97-e922-457c-bbf3-dsadeqac") .withFieldName("access_log_topic_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("2020-07-14T19:57:36+08:00") .withFieldName("time_iso8601") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("elb_01") .withFieldName("log_ver") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("192.0.0.0") .withFieldName("remote_addr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("88888") .withFieldName("remote_port") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("200") .withFieldName("status") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("GET") .withFieldName("request_method") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("http") .withFieldName("scheme") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("prod.sss.ads.sg2.aaa") .withFieldName("host") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .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() .withContent("HTTP/1.1") .withFieldName("server_protocol") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("233") .withFieldName("request_length") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("293") .withFieldName("bytes_sent") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("138") .withFieldName("body_bytes_sent") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("0.001") .withFieldName("request_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("200") .withFieldName("upstream_status") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("0.000") .withFieldName("upstream_connect_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("0.001") .withFieldName("upstream_header_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("0.001") .withFieldName("upstream_response_time") .withType("float") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("100.0.0.0:9999") .withFieldName("upstream_addr") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("lua-resty-http/0.14 (Lua) ngx_lua/10000") .withFieldName("http_user_agent") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("http_referer") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("http_x_forwarded_for") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa") .withFieldName("lb_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("listener_6077809b-913f-466d-a96c-376f08882d5d") .withFieldName("listener_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("08cc2b3f68aa4dddd1e6a90dddd1688348a4480") .withFieldName("listener_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b") .withFieldName("pool_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("member_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("2fb78dsadadq1213das1121dab146ad3cb0") .withFieldName("tenant_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("eip_address") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("80") .withFieldName("eip_port") .withType("long") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("101.0.0.0:10000") .withFieldName("upstream_addr_priv") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("certificate_id") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("ssl_protocol") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("ssl_cipher") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("-") .withFieldName("sni_domain_name") .withType("string") ); listbodyDemoFields.add( new StructFieldInfo() .withContent("9739") .withFieldName("tcpinfo_rtt") .withType("long") ); body.withRule(rulebody); body.withProjectId(" "); body.withLogStreamId(" "); body.withParseType(LtsStructTemplateInfo.ParseTypeEnum.fromValue(" ")); body.withLogGroupId(" "); 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 { UpdateStructTemplateResponse response = client.updateStructTemplate(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
# 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 = UpdateStructTemplateRequest() rulebody = Rule( type="built_in", param="VPC" ) listTagFieldsbody = [ TagField( field_name="hostIP", type="string", content="192.168.2.134", is_analysis=True ) ] listDemoFieldsbody = [ StructFieldInfo( content="1", field_name="version", type="long" ), StructFieldInfo( content="5f67944957444bd6bb4fe3b367de8f3d", field_name="project_id", type="string" ), StructFieldInfo( content="1d515d18-1b36-47dc-a983-bd6512aed4bd", field_name="interface_id", type="string" ), StructFieldInfo( content="192.168.0.154", field_name="srcaddr", type="string" ), StructFieldInfo( content="192.168.3.25", field_name="dstaddr", type="string" ), StructFieldInfo( content="38929", field_name="srcport", type="long" ), StructFieldInfo( content="53", field_name="dstport", type="long" ), StructFieldInfo( content="17", field_name="protocol", type="long" ), StructFieldInfo( content="1", field_name="packets", type="long" ), StructFieldInfo( content="96", field_name="bytes", type="long" ), StructFieldInfo( content="1548752136", field_name="start", type="long" ), StructFieldInfo( content="1548752736", field_name="end", type="long" ), StructFieldInfo( content="ACCEPT", field_name="action", type="string" ), StructFieldInfo( content="OK", field_name="log_status", type="string" ) ] request.body = LtsStructTemplateInfo( rule=rulebody, project_id=" ", log_stream_id=" ", parse_type=" ", log_group_id=" ", 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.update_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
# 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 = UpdateStructTemplateRequest() rulebody = Rule( type="built_in", param="ELB" ) listTagFieldsbody = [ TagField( field_name="hostIP", type="string", content="192.168.2.134", is_analysis=True ) ] listDemoFieldsbody = [ StructFieldInfo( content="1594727856.337", field_name="msec", type="float" ), StructFieldInfo( content="e7c37d97-e922-457c-bbf3-dsadeqac", field_name="access_log_topic_id", type="string" ), StructFieldInfo( content="2020-07-14T19:57:36+08:00", field_name="time_iso8601", type="string" ), StructFieldInfo( content="elb_01", field_name="log_ver", type="string" ), StructFieldInfo( content="192.0.0.0", field_name="remote_addr", type="string" ), StructFieldInfo( content="88888", field_name="remote_port", type="long" ), StructFieldInfo( content="200", field_name="status", type="long" ), StructFieldInfo( content="GET", field_name="request_method", type="string" ), StructFieldInfo( content="http", field_name="scheme", type="string" ), StructFieldInfo( content="prod.sss.ads.sg2.aaa", field_name="host", type="string" ), StructFieldInfo( 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( content="HTTP/1.1", field_name="server_protocol", type="string" ), StructFieldInfo( content="233", field_name="request_length", type="long" ), StructFieldInfo( content="293", field_name="bytes_sent", type="long" ), StructFieldInfo( content="138", field_name="body_bytes_sent", type="long" ), StructFieldInfo( content="0.001", field_name="request_time", type="float" ), StructFieldInfo( content="200", field_name="upstream_status", type="long" ), StructFieldInfo( content="0.000", field_name="upstream_connect_time", type="float" ), StructFieldInfo( content="0.001", field_name="upstream_header_time", type="float" ), StructFieldInfo( content="0.001", field_name="upstream_response_time", type="float" ), StructFieldInfo( content="100.0.0.0:9999", field_name="upstream_addr", type="string" ), StructFieldInfo( content="lua-resty-http/0.14 (Lua) ngx_lua/10000", field_name="http_user_agent", type="string" ), StructFieldInfo( content="-", field_name="http_referer", type="string" ), StructFieldInfo( content="-", field_name="http_x_forwarded_for", type="string" ), StructFieldInfo( content="loadbalancer_edsaee-4c9c-b467-5b8126b2f7f7dsa", field_name="lb_name", type="string" ), StructFieldInfo( content="listener_6077809b-913f-466d-a96c-376f08882d5d", field_name="listener_name", type="string" ), StructFieldInfo( content="08cc2b3f68aa4dddd1e6a90dddd1688348a4480", field_name="listener_id", type="string" ), StructFieldInfo( content="pool_b2f2966c-043d-4674-ad4b-c15f2adb2c6b", field_name="pool_name", type="string" ), StructFieldInfo( content="-", field_name="member_name", type="string" ), StructFieldInfo( content="2fb78dsadadq1213das1121dab146ad3cb0", field_name="tenant_id", type="string" ), StructFieldInfo( content="-", field_name="eip_address", type="string" ), StructFieldInfo( content="80", field_name="eip_port", type="long" ), StructFieldInfo( content="101.0.0.0:10000", field_name="upstream_addr_priv", type="string" ), StructFieldInfo( content="-", field_name="certificate_id", type="string" ), StructFieldInfo( content="-", field_name="ssl_protocol", type="string" ), StructFieldInfo( content="-", field_name="ssl_cipher", type="string" ), StructFieldInfo( content="-", field_name="sni_domain_name", type="string" ), StructFieldInfo( content="9739", field_name="tcpinfo_rtt", type="long" ) ] request.body = LtsStructTemplateInfo( rule=rulebody, project_id=" ", log_stream_id=" ", parse_type=" ", log_group_id=" ", 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.update_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。 被请求的服务无效, 服务不可用。 |
错误码
请参见错误码。