Creating a Collection Parser
Function
This API is used to create a collection parser.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/workspaces/{workspace_id}/collector/logstash/parsers
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Definition Project ID, which is used to specify the project that a resource belongs to. You can query the resources of a project by project ID. You can obtain the project ID from the API or console. Obtaining the Project ID Constraints N/A Value Range N/A Default value N/A |
|
workspace_id |
Yes |
String |
Workspace ID. |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
X-Auth-Token |
Yes |
String |
Definition User token. You can obtain it by calling the IAM API for obtaining a user token. The user token is the value of X-Subject-Token in the response header. Obtaining a User Token Constraints N/A Range N/A Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
description |
No |
String |
Description. |
|
modules |
No |
Array of CreateModuleVo objects |
Description. |
|
parser_id |
No |
String |
UUID |
|
title |
Yes |
String |
Related title. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
children |
No |
Array of CreateModuleVo objects |
Description. |
|
connection_module_id |
No |
String |
UUID |
|
fields |
No |
Array of ModuleFieldVo objects |
Description. |
|
name |
No |
String |
Name. |
|
template_id |
No |
String |
UUID |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
parser_id |
String |
UUID |
Example Requests
https://{endpoint}/v1/{project_id}/workspaces/{workspace_id}/collector/logstash/parsers
{
"title" : "myparser",
"description" : "",
"modules" : [ {
"name" : "uuid",
"children" : null,
"template_id" : "96fdd10e-48c6-4ec7-9d3b-f92df467e5f1",
"fields" : [ {
"template_field_id" : "b0ff2304-ce9b-451d-ad8f-7475c6d878b5",
"name" : "target",
"type" : "string",
"value" : "uuid"
}, {
"template_field_id" : "1d47501e-539f-49f5-8ceb-20c9f85a4947",
"name" : "overwrite",
"type" : "boolean",
"value" : true
} ]
}, {
"name" : "json",
"children" : null,
"template_id" : "f7a38175-378c-479e-94aa-2e3ddc416f7c",
"fields" : [ {
"template_field_id" : "276f36f8-3025-42c8-8370-a876080185d4",
"name" : "source",
"type" : "string",
"value" : "message"
} ]
} ]
}
Example Responses
Status code: 200
Successful.
{
"parser_id" : "adca0d1b-9b4a-4543-9918-026455cf8825"
}
SDK Sample Code
The SDK sample code is as follows.
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 |
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.secmaster.v1.region.SecMasterRegion; import com.huaweicloud.sdk.secmaster.v1.*; import com.huaweicloud.sdk.secmaster.v1.model.*; import java.util.List; import java.util.ArrayList; public class CreateCollectorParserSolution { 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); SecMasterClient client = SecMasterClient.newBuilder() .withCredential(auth) .withRegion(SecMasterRegion.valueOf("<YOUR REGION>")) .build(); CreateCollectorParserRequest request = new CreateCollectorParserRequest(); request.withWorkspaceId("{workspace_id}"); CreateParserDto body = new CreateParserDto(); List<ModuleFieldVo> listModulesFields = new ArrayList<>(); listModulesFields.add( new ModuleFieldVo() .withName("source") .withTemplateFieldId("276f36f8-3025-42c8-8370-a876080185d4") .withType("string") .withValue("message") ); List<ModuleFieldVo> listModulesFields1 = new ArrayList<>(); listModulesFields1.add( new ModuleFieldVo() .withName("target") .withTemplateFieldId("b0ff2304-ce9b-451d-ad8f-7475c6d878b5") .withType("string") .withValue("uuid") ); listModulesFields1.add( new ModuleFieldVo() .withName("overwrite") .withTemplateFieldId("1d47501e-539f-49f5-8ceb-20c9f85a4947") .withType("boolean") .withValue("true") ); List<CreateModuleVo> listbodyModules = new ArrayList<>(); listbodyModules.add( new CreateModuleVo() .withFields(listModulesFields) .withName("json") .withTemplateId("f7a38175-378c-479e-94aa-2e3ddc416f7c") ); listbodyModules.add( new CreateModuleVo() .withFields(listModulesFields1) .withName("uuid") .withTemplateId("96fdd10e-48c6-4ec7-9d3b-f92df467e5f1") ); body.withTitle("myparser"); body.withModules(listbodyModules); body.withDescription(""); request.withBody(body); try { CreateCollectorParserResponse response = client.createCollectorParser(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()); } } } |
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 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdksecmaster.v1.region.secmaster_region import SecMasterRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdksecmaster.v1 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 = SecMasterClient.new_builder() \ .with_credentials(credentials) \ .with_region(SecMasterRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateCollectorParserRequest() request.workspace_id = "{workspace_id}" listFieldsModules = [ ModuleFieldVo( name="source", template_field_id="276f36f8-3025-42c8-8370-a876080185d4", type="string", value="message" ) ] listFieldsModules1 = [ ModuleFieldVo( name="target", template_field_id="b0ff2304-ce9b-451d-ad8f-7475c6d878b5", type="string", value="uuid" ), ModuleFieldVo( name="overwrite", template_field_id="1d47501e-539f-49f5-8ceb-20c9f85a4947", type="boolean", value="true" ) ] listModulesbody = [ CreateModuleVo( fields=listFieldsModules, name="json", template_id="f7a38175-378c-479e-94aa-2e3ddc416f7c" ), CreateModuleVo( fields=listFieldsModules1, name="uuid", template_id="96fdd10e-48c6-4ec7-9d3b-f92df467e5f1" ) ] request.body = CreateParserDto( title="myparser", modules=listModulesbody, description="" ) response = client.create_collector_parser(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
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 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" secmaster "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/secmaster/v1/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 := secmaster.NewSecMasterClient( secmaster.SecMasterClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.CreateCollectorParserRequest{} request.WorkspaceId = "{workspace_id}" nameFields:= "source" templateFieldIdFields:= "276f36f8-3025-42c8-8370-a876080185d4" typeFields:= "string" valueFields:= "message" var listFieldsModules = []model.ModuleFieldVo{ { Name: &nameFields, TemplateFieldId: &templateFieldIdFields, Type: &typeFields, Value: &valueFields, }, } nameFields1:= "target" templateFieldIdFields1:= "b0ff2304-ce9b-451d-ad8f-7475c6d878b5" typeFields1:= "string" valueFields1:= "uuid" nameFields2:= "overwrite" templateFieldIdFields2:= "1d47501e-539f-49f5-8ceb-20c9f85a4947" typeFields2:= "boolean" valueFields2:= "true" var listFieldsModules1 = []model.ModuleFieldVo{ { Name: &nameFields1, TemplateFieldId: &templateFieldIdFields1, Type: &typeFields1, Value: &valueFields1, }, { Name: &nameFields2, TemplateFieldId: &templateFieldIdFields2, Type: &typeFields2, Value: &valueFields2, }, } nameModules1:= "json" templateIdModules1:= "f7a38175-378c-479e-94aa-2e3ddc416f7c" nameModules:= "uuid" templateIdModules:= "96fdd10e-48c6-4ec7-9d3b-f92df467e5f1" var listModulesbody = []model.CreateModuleVo{ { Fields: &listFieldsModules, Name: &nameModules1, TemplateId: &templateIdModules1, }, { Fields: &listFieldsModules1, Name: &nameModules, TemplateId: &templateIdModules, }, } descriptionCreateParserDto:= "" request.Body = &model.CreateParserDto{ Title: "myparser", Modules: &listModulesbody, Description: &descriptionCreateParserDto, } response, err := client.CreateCollectorParser(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 |
|---|---|
|
200 |
Successful. |
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