Creating Structuring Configurations (Recommended)
Function
This API is used to create structuring configurations using a structuring template, which facilitates parameter extraction and simplifies the parameter structure. A user can call this API only once per second.
Calling Method
For details, see Calling APIs.
URI
POST /v3/{project_id}/lts/struct/template
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Project ID. For details about how to obtain a project ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID. Minimum: 32 Maximum: 32 |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
User token obtained from IAM. For details about how to obtain a user token, see Obtaining a User Token. Minimum: 1000 Maximum: 2000 |
Content-Type |
Yes |
String |
Set this parameter to application/json;charset=UTF-8. Minimum: 30 Maximum: 30 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
log_group_id |
Yes |
String |
Project ID. For details about how to obtain a project ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID. Minimum: 36 Maximum: 36 |
log_stream_id |
Yes |
String |
Project ID. For details about how to obtain a project ID, see Obtaining the Project ID, Account ID, Log Group ID, and Log Stream ID. Minimum: 36 Maximum: 36 |
template_id |
Yes |
String |
Template ID. When the system template is used, the current attribute can be empty. Minimum: 0 Maximum: 36 |
template_name |
Yes |
String |
Template name. The template name and ID will be verified. Minimum: 1 Maximum: 64 |
template_type |
Yes |
String |
Type of the template. The value can be built_in (system templates) or custom (custom templates). For details about system template types, see section "Log Search and Analysis" > "Cloud Structuring Parsing" > "Structuring Templates" in the LTS User Guide. Enumeration values:
|
demo_fields |
No |
Array of FieldModel objects |
Example field array. You only need to enter the fields whose status is different from that of is_analysis in the template. |
tag_fields |
No |
Array of FieldModel objects |
Tag field array. You only need to enter the fields whose status is different from that of is_analysis in the template. |
quick_analysis |
No |
Boolean |
Indicates whether to enable quick analysis for demo_fields and tag_fields. If this parameter is set to true, quick analysis is enabled for all fields. If this parameter is left blank or set to false, is_analysis in the template is used to determine whether to enable quick analysis. |
Response Parameters
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. Minimum: 8 Maximum: 8 |
error_msg |
String |
Error message. Enumeration values:
|
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. Minimum: 8 Maximum: 8 |
error_msg |
String |
Error message. |
Example Requests
Creating an ELB System 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 }
Creating a VPC System 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 }
Example Responses
Status code: 201
The request is successful.
Status code: 400
Invalid request. Modify the request based on the description in error_msg before a retry.
{ "error_code" : "LTS.2014", "error_msg" : "template_id is invalid!" }
Status code: 500
The server has received the request but encountered an internal error.
{ "error_code" : "LTS.2014", "error_msg" : "Failed to create struct config." }
SDK Sample Code
The SDK sample code is as follows.
Creating an ELB System Template
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
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"); ICredential auth = new BasicCredentials() .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()); } } }
Creating a VPC System Template
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
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"); ICredential auth = new BasicCredentials() .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()); } } }
Creating an ELB System Template
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
# 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"] credentials = BasicCredentials(ak, sk) 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)
Creating a VPC System Template
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
# 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"] credentials = BasicCredentials(ak, sk) 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)
Creating an ELB System Template
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
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). 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) } }
Creating a VPC System Template
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
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") auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). 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) } }
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
201 |
The request is successful. |
400 |
Invalid request. Modify the request based on the description in error_msg before a retry. |
500 |
The server has received the request but encountered an internal error. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot