创建结构化配置(推荐)
功能介绍
该接口通过结构化模板创建结构化配置,便于参数提取且简化参数结构,推荐您使用。
单个用户每秒仅能调用1次该接口。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/lts/struct/template
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID 最小长度:32 最大长度:32 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token,获取方式请参见:获取用户Token 最小长度:1000 最大长度:2000 |
Content-Type |
是 |
String |
该字段填为:application/json;charset=UTF-8。 最小长度:30 最大长度:30 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
log_group_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID 最小长度:36 最大长度:36 |
log_stream_id |
是 |
String |
项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID 最小长度:36 最大长度:36 |
template_id |
是 |
String |
所用模板id。当使用系统模板时,当前属性可以为空 最小长度:0 最大长度:36 |
template_name |
是 |
String |
所用模板名称,会对模板名称及id进行校验 最小长度:1 最大长度:64 |
template_type |
是 |
String |
所用模板类型,分为built_in及custom两种类型,对应系统模板和自定义模板, 详细系统模板类型参考:“用户指南-日志搜索与分析(默认推荐)> 云端结构化解析> 结构化模板”章节。 |
demo_fields |
否 |
Array of FieldModel objects |
示例字段数组,填写与模板中is_analysis参数状态不同的字段。 |
tag_fields |
否 |
Array of FieldModel objects |
Tag字段数组,填写与模板中is_analysis参数状态不同的字段。 |
quick_analysis |
否 |
Boolean |
是否开启demo_fields和tag_fields快速分析,为true时,所有的demo_fields和tag_fields全部字段均打开快速分析;不填或者为false,以模板中的demo_fields和tag_fields中的is_analysis决定是否开启快速分析。 |
响应参数
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码 最小长度:8 最大长度:8 |
error_msg |
String |
调用失败响应信息描述 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码。 最小长度:8 最大长度:8 |
error_msg |
String |
调用失败响应信息描述。 |
请求示例
-
创建ELB系统模板
POST https://{endpoint}/v3/{project_id}/lts/struct/template { "log_group_id" : "17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx", "log_stream_id" : "b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", "demo_fields" : [ { "field_name" : "msec", "is_analysis" : false }, { "field_name" : "access_log_topic_id", "is_analysis" : false }, { "field_name" : "time_iso8601", "is_analysis" : false }, { "field_name" : "log_ver", "is_analysis" : true }, { "field_name" : "remote_addr", "is_analysis" : true }, { "field_name" : "remote_port", "is_analysis" : false }, { "field_name" : "status", "is_analysis" : false }, { "field_name" : "request_method", "is_analysis" : false }, { "field_name" : "scheme", "is_analysis" : true }, { "field_name" : "host", "is_analysis" : true }, { "field_name" : "router_request_uri", "is_analysis" : true }, { "field_name" : "server_protocol", "is_analysis" : true }, { "field_name" : "request_length", "is_analysis" : true }, { "field_name" : "bytes_sent", "is_analysis" : false }, { "field_name" : "body_bytes_sent", "is_analysis" : false }, { "field_name" : "request_time", "is_analysis" : false }, { "field_name" : "upstream_status", "is_analysis" : false }, { "field_name" : "upstream_connect_time", "is_analysis" : false }, { "field_name" : "upstream_header_time", "is_analysis" : false }, { "field_name" : "upstream_response_time", "is_analysis" : false }, { "field_name" : "upstream_addr", "is_analysis" : false }, { "field_name" : "http_user_agent", "is_analysis" : false }, { "field_name" : "http_referer", "is_analysis" : false }, { "field_name" : "http_x_forwarded_for", "is_analysis" : false }, { "field_name" : "lb_name", "is_analysis" : false }, { "field_name" : "listener_name", "is_analysis" : false }, { "field_name" : "listener_id", "is_analysis" : false }, { "field_name" : "pool_name", "is_analysis" : false }, { "field_name" : "member_name", "is_analysis" : false }, { "field_name" : "tenant_id", "is_analysis" : false }, { "field_name" : "eip_address", "is_analysis" : false }, { "field_name" : "eip_port", "is_analysis" : false }, { "field_name" : "upstream_addr_priv", "is_analysis" : false }, { "field_name" : "certificate_id", "is_analysis" : false }, { "field_name" : "ssl_protocol", "is_analysis" : false }, { "field_name" : "ssl_cipher", "is_analysis" : false }, { "field_name" : "sni_domain_name", "is_analysis" : false }, { "field_name" : "tcpinfo_rtt", "is_analysis" : false } ], "tag_fields" : [ { "field_name" : "hostIP", "is_analysis" : true } ], "template_type" : "built_in", "template_name" : "ELB", "template_id" : "", "quick_analysis" : false }
-
创建VPC系统模板
POST https://{endpoint}/v3/{project_id}/lts/struct/template { "log_group_id" : "17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx", "log_stream_id" : "b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", "demo_fields" : [ { "field_name" : "version", "is_analysis" : false }, { "field_name" : "project_id", "is_analysis" : true }, { "field_name" : "interface_id", "is_analysis" : false }, { "field_name" : "srcaddr", "is_analysis" : true }, { "field_name" : "dstaddr", "is_analysis" : true }, { "field_name" : "srcport", "is_analysis" : false }, { "field_name" : "dstport", "is_analysis" : false }, { "field_name" : "protocol", "is_analysis" : false }, { "field_name" : "packets", "is_analysis" : false }, { "field_name" : "bytes", "is_analysis" : false }, { "field_name" : "start", "is_analysis" : false }, { "field_name" : "end", "is_analysis" : false }, { "field_name" : "action", "is_analysis" : true }, { "field_name" : "log_status", "is_analysis" : true } ], "tag_fields" : [ { "field_name" : "hostIP", "is_analysis" : true } ], "template_type" : "built_in", "template_name" : "VPC", "template_id" : "", "quick_analysis" : false }
响应示例
状态码: 201
请求响应成功。
状态码: 400
BadRequest 非法请求 建议根据error_msg直接修改该请求。
{ "error_code" : "LTS.2014", "error_msg" : "template_id is invalid!" }
状态码: 500
表明服务端能被请求访问到,但是服务内部出错。
{ "error_code" : "LTS.2014", "error_msg" : "Failed to create struct config." }
SDK代码示例
SDK代码示例如下。
-
创建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
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 CreateStructConfigSolution { 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(); CreateStructConfigRequest request = new CreateStructConfigRequest(); StructConfig body = new StructConfig(); List<FieldModel> listbodyTagFields = new ArrayList<>(); listbodyTagFields.add( new FieldModel() .withFieldName("hostIP") .withIsAnalysis(true) ); List<FieldModel> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new FieldModel() .withFieldName("msec") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("access_log_topic_id") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("time_iso8601") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("log_ver") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("remote_addr") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("remote_port") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("status") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("request_method") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("scheme") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("host") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("router_request_uri") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("server_protocol") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("request_length") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("bytes_sent") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("body_bytes_sent") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("request_time") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_status") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_connect_time") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_header_time") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_response_time") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_addr") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("http_user_agent") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("http_referer") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("http_x_forwarded_for") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("lb_name") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("listener_name") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("listener_id") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("pool_name") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("member_name") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("tenant_id") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("eip_address") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("eip_port") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("upstream_addr_priv") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("certificate_id") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("ssl_protocol") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("ssl_cipher") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("sni_domain_name") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("tcpinfo_rtt") .withIsAnalysis(false) ); body.withQuickAnalysis(false); body.withTagFields(listbodyTagFields); body.withDemoFields(listbodyDemoFields); body.withTemplateType(StructConfig.TemplateTypeEnum.fromValue("built_in")); body.withTemplateName("ELB"); body.withTemplateId(""); body.withLogStreamId("b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx"); body.withLogGroupId("17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx"); request.withBody(body); try { CreateStructConfigResponse response = client.createStructConfig(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
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 CreateStructConfigSolution { 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(); CreateStructConfigRequest request = new CreateStructConfigRequest(); StructConfig body = new StructConfig(); List<FieldModel> listbodyTagFields = new ArrayList<>(); listbodyTagFields.add( new FieldModel() .withFieldName("hostIP") .withIsAnalysis(true) ); List<FieldModel> listbodyDemoFields = new ArrayList<>(); listbodyDemoFields.add( new FieldModel() .withFieldName("version") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("project_id") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("interface_id") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("srcaddr") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("dstaddr") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("srcport") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("dstport") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("protocol") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("packets") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("bytes") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("start") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("end") .withIsAnalysis(false) ); listbodyDemoFields.add( new FieldModel() .withFieldName("action") .withIsAnalysis(true) ); listbodyDemoFields.add( new FieldModel() .withFieldName("log_status") .withIsAnalysis(true) ); body.withQuickAnalysis(false); body.withTagFields(listbodyTagFields); body.withDemoFields(listbodyDemoFields); body.withTemplateType(StructConfig.TemplateTypeEnum.fromValue("built_in")); body.withTemplateName("VPC"); body.withTemplateId(""); body.withLogStreamId("b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx"); body.withLogGroupId("17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx"); request.withBody(body); try { CreateStructConfigResponse response = client.createStructConfig(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
# 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 = CreateStructConfigRequest() listTagFieldsbody = [ FieldModel( field_name="hostIP", is_analysis=True ) ] listDemoFieldsbody = [ FieldModel( field_name="msec", is_analysis=False ), FieldModel( field_name="access_log_topic_id", is_analysis=False ), FieldModel( field_name="time_iso8601", is_analysis=False ), FieldModel( field_name="log_ver", is_analysis=True ), FieldModel( field_name="remote_addr", is_analysis=True ), FieldModel( field_name="remote_port", is_analysis=False ), FieldModel( field_name="status", is_analysis=False ), FieldModel( field_name="request_method", is_analysis=False ), FieldModel( field_name="scheme", is_analysis=True ), FieldModel( field_name="host", is_analysis=True ), FieldModel( field_name="router_request_uri", is_analysis=True ), FieldModel( field_name="server_protocol", is_analysis=True ), FieldModel( field_name="request_length", is_analysis=True ), FieldModel( field_name="bytes_sent", is_analysis=False ), FieldModel( field_name="body_bytes_sent", is_analysis=False ), FieldModel( field_name="request_time", is_analysis=False ), FieldModel( field_name="upstream_status", is_analysis=False ), FieldModel( field_name="upstream_connect_time", is_analysis=False ), FieldModel( field_name="upstream_header_time", is_analysis=False ), FieldModel( field_name="upstream_response_time", is_analysis=False ), FieldModel( field_name="upstream_addr", is_analysis=False ), FieldModel( field_name="http_user_agent", is_analysis=False ), FieldModel( field_name="http_referer", is_analysis=False ), FieldModel( field_name="http_x_forwarded_for", is_analysis=False ), FieldModel( field_name="lb_name", is_analysis=False ), FieldModel( field_name="listener_name", is_analysis=False ), FieldModel( field_name="listener_id", is_analysis=False ), FieldModel( field_name="pool_name", is_analysis=False ), FieldModel( field_name="member_name", is_analysis=False ), FieldModel( field_name="tenant_id", is_analysis=False ), FieldModel( field_name="eip_address", is_analysis=False ), FieldModel( field_name="eip_port", is_analysis=False ), FieldModel( field_name="upstream_addr_priv", is_analysis=False ), FieldModel( field_name="certificate_id", is_analysis=False ), FieldModel( field_name="ssl_protocol", is_analysis=False ), FieldModel( field_name="ssl_cipher", is_analysis=False ), FieldModel( field_name="sni_domain_name", is_analysis=False ), FieldModel( field_name="tcpinfo_rtt", is_analysis=False ) ] request.body = StructConfig( quick_analysis=False, tag_fields=listTagFieldsbody, demo_fields=listDemoFieldsbody, template_type="built_in", template_name="ELB", template_id="", log_stream_id="b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", log_group_id="17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx" ) response = client.create_struct_config(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系统模板
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
# 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 = CreateStructConfigRequest() listTagFieldsbody = [ FieldModel( field_name="hostIP", is_analysis=True ) ] listDemoFieldsbody = [ FieldModel( field_name="version", is_analysis=False ), FieldModel( field_name="project_id", is_analysis=True ), FieldModel( field_name="interface_id", is_analysis=False ), FieldModel( field_name="srcaddr", is_analysis=True ), FieldModel( field_name="dstaddr", is_analysis=True ), FieldModel( field_name="srcport", is_analysis=False ), FieldModel( field_name="dstport", is_analysis=False ), FieldModel( field_name="protocol", is_analysis=False ), FieldModel( field_name="packets", is_analysis=False ), FieldModel( field_name="bytes", is_analysis=False ), FieldModel( field_name="start", is_analysis=False ), FieldModel( field_name="end", is_analysis=False ), FieldModel( field_name="action", is_analysis=True ), FieldModel( field_name="log_status", is_analysis=True ) ] request.body = StructConfig( quick_analysis=False, tag_fields=listTagFieldsbody, demo_fields=listDemoFieldsbody, template_type="built_in", template_name="VPC", template_id="", log_stream_id="b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", log_group_id="17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx" ) response = client.create_struct_config(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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateStructConfigRequest{} isAnalysisTagFields:= true var listTagFieldsbody = []model.FieldModel{ { FieldName: "hostIP", IsAnalysis: &isAnalysisTagFields, }, } isAnalysisDemoFields:= false isAnalysisDemoFields1:= false isAnalysisDemoFields2:= false isAnalysisDemoFields3:= true isAnalysisDemoFields4:= true isAnalysisDemoFields5:= false isAnalysisDemoFields6:= false isAnalysisDemoFields7:= false isAnalysisDemoFields8:= true isAnalysisDemoFields9:= true isAnalysisDemoFields10:= true isAnalysisDemoFields11:= true isAnalysisDemoFields12:= true isAnalysisDemoFields13:= false isAnalysisDemoFields14:= false isAnalysisDemoFields15:= false isAnalysisDemoFields16:= false isAnalysisDemoFields17:= false isAnalysisDemoFields18:= false isAnalysisDemoFields19:= false isAnalysisDemoFields20:= false isAnalysisDemoFields21:= false isAnalysisDemoFields22:= false isAnalysisDemoFields23:= false isAnalysisDemoFields24:= false isAnalysisDemoFields25:= false isAnalysisDemoFields26:= false isAnalysisDemoFields27:= false isAnalysisDemoFields28:= false isAnalysisDemoFields29:= false isAnalysisDemoFields30:= false isAnalysisDemoFields31:= false isAnalysisDemoFields32:= false isAnalysisDemoFields33:= false isAnalysisDemoFields34:= false isAnalysisDemoFields35:= false isAnalysisDemoFields36:= false isAnalysisDemoFields37:= false var listDemoFieldsbody = []model.FieldModel{ { FieldName: "msec", IsAnalysis: &isAnalysisDemoFields, }, { FieldName: "access_log_topic_id", IsAnalysis: &isAnalysisDemoFields1, }, { FieldName: "time_iso8601", IsAnalysis: &isAnalysisDemoFields2, }, { FieldName: "log_ver", IsAnalysis: &isAnalysisDemoFields3, }, { FieldName: "remote_addr", IsAnalysis: &isAnalysisDemoFields4, }, { FieldName: "remote_port", IsAnalysis: &isAnalysisDemoFields5, }, { FieldName: "status", IsAnalysis: &isAnalysisDemoFields6, }, { FieldName: "request_method", IsAnalysis: &isAnalysisDemoFields7, }, { FieldName: "scheme", IsAnalysis: &isAnalysisDemoFields8, }, { FieldName: "host", IsAnalysis: &isAnalysisDemoFields9, }, { FieldName: "router_request_uri", IsAnalysis: &isAnalysisDemoFields10, }, { FieldName: "server_protocol", IsAnalysis: &isAnalysisDemoFields11, }, { FieldName: "request_length", IsAnalysis: &isAnalysisDemoFields12, }, { FieldName: "bytes_sent", IsAnalysis: &isAnalysisDemoFields13, }, { FieldName: "body_bytes_sent", IsAnalysis: &isAnalysisDemoFields14, }, { FieldName: "request_time", IsAnalysis: &isAnalysisDemoFields15, }, { FieldName: "upstream_status", IsAnalysis: &isAnalysisDemoFields16, }, { FieldName: "upstream_connect_time", IsAnalysis: &isAnalysisDemoFields17, }, { FieldName: "upstream_header_time", IsAnalysis: &isAnalysisDemoFields18, }, { FieldName: "upstream_response_time", IsAnalysis: &isAnalysisDemoFields19, }, { FieldName: "upstream_addr", IsAnalysis: &isAnalysisDemoFields20, }, { FieldName: "http_user_agent", IsAnalysis: &isAnalysisDemoFields21, }, { FieldName: "http_referer", IsAnalysis: &isAnalysisDemoFields22, }, { FieldName: "http_x_forwarded_for", IsAnalysis: &isAnalysisDemoFields23, }, { FieldName: "lb_name", IsAnalysis: &isAnalysisDemoFields24, }, { FieldName: "listener_name", IsAnalysis: &isAnalysisDemoFields25, }, { FieldName: "listener_id", IsAnalysis: &isAnalysisDemoFields26, }, { FieldName: "pool_name", IsAnalysis: &isAnalysisDemoFields27, }, { FieldName: "member_name", IsAnalysis: &isAnalysisDemoFields28, }, { FieldName: "tenant_id", IsAnalysis: &isAnalysisDemoFields29, }, { FieldName: "eip_address", IsAnalysis: &isAnalysisDemoFields30, }, { FieldName: "eip_port", IsAnalysis: &isAnalysisDemoFields31, }, { FieldName: "upstream_addr_priv", IsAnalysis: &isAnalysisDemoFields32, }, { FieldName: "certificate_id", IsAnalysis: &isAnalysisDemoFields33, }, { FieldName: "ssl_protocol", IsAnalysis: &isAnalysisDemoFields34, }, { FieldName: "ssl_cipher", IsAnalysis: &isAnalysisDemoFields35, }, { FieldName: "sni_domain_name", IsAnalysis: &isAnalysisDemoFields36, }, { FieldName: "tcpinfo_rtt", IsAnalysis: &isAnalysisDemoFields37, }, } quickAnalysisStructConfig:= false request.Body = &model.StructConfig{ QuickAnalysis: &quickAnalysisStructConfig, TagFields: &listTagFieldsbody, DemoFields: &listDemoFieldsbody, TemplateType: model.GetStructConfigTemplateTypeEnum().BUILT_IN, TemplateName: "ELB", TemplateId: "", LogStreamId: "b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", LogGroupId: "17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx", } response, err := client.CreateStructConfig(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := lts.NewLtsClient( lts.LtsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateStructConfigRequest{} isAnalysisTagFields:= true var listTagFieldsbody = []model.FieldModel{ { FieldName: "hostIP", IsAnalysis: &isAnalysisTagFields, }, } isAnalysisDemoFields:= false isAnalysisDemoFields1:= true isAnalysisDemoFields2:= false isAnalysisDemoFields3:= true isAnalysisDemoFields4:= true isAnalysisDemoFields5:= false isAnalysisDemoFields6:= false isAnalysisDemoFields7:= false isAnalysisDemoFields8:= false isAnalysisDemoFields9:= false isAnalysisDemoFields10:= false isAnalysisDemoFields11:= false isAnalysisDemoFields12:= true isAnalysisDemoFields13:= true var listDemoFieldsbody = []model.FieldModel{ { FieldName: "version", IsAnalysis: &isAnalysisDemoFields, }, { FieldName: "project_id", IsAnalysis: &isAnalysisDemoFields1, }, { FieldName: "interface_id", IsAnalysis: &isAnalysisDemoFields2, }, { FieldName: "srcaddr", IsAnalysis: &isAnalysisDemoFields3, }, { FieldName: "dstaddr", IsAnalysis: &isAnalysisDemoFields4, }, { FieldName: "srcport", IsAnalysis: &isAnalysisDemoFields5, }, { FieldName: "dstport", IsAnalysis: &isAnalysisDemoFields6, }, { FieldName: "protocol", IsAnalysis: &isAnalysisDemoFields7, }, { FieldName: "packets", IsAnalysis: &isAnalysisDemoFields8, }, { FieldName: "bytes", IsAnalysis: &isAnalysisDemoFields9, }, { FieldName: "start", IsAnalysis: &isAnalysisDemoFields10, }, { FieldName: "end", IsAnalysis: &isAnalysisDemoFields11, }, { FieldName: "action", IsAnalysis: &isAnalysisDemoFields12, }, { FieldName: "log_status", IsAnalysis: &isAnalysisDemoFields13, }, } quickAnalysisStructConfig:= false request.Body = &model.StructConfig{ QuickAnalysis: &quickAnalysisStructConfig, TagFields: &listTagFieldsbody, DemoFields: &listDemoFieldsbody, TemplateType: model.GetStructConfigTemplateTypeEnum().BUILT_IN, TemplateName: "VPC", TemplateId: "", LogStreamId: "b4d56d47-b4c4-453e-9047-xxxxxxxxxxxx", LogGroupId: "17f23e52-a23d-46e0-8bc5-xxxxxxxxxxxx", } response, err := client.CreateStructConfig(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
201 |
请求响应成功。 |
400 |
BadRequest 非法请求 建议根据error_msg直接修改该请求。 |
500 |
表明服务端能被请求访问到,但是服务内部出错。 |
错误码
请参见错误码。