Saving Cloud Service Log Collection Configuration
Function
This API is used to save cloud service collection configurations.
Calling Method
For details, see Calling APIs.
URI
POST /v1/{project_id}/collector/cloudlogs/config
|
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 |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
region_id |
No |
String |
Region 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 |
|---|---|---|---|
|
config |
Yes |
Array of ConfigInfo objects |
Dataset list. |
|
dataspace_id |
Yes |
String |
Data space ID. |
|
dataspace_name |
Yes |
String |
Data space name. |
|
domain_id |
No |
String |
Account ID. |
|
lts_config |
No |
Array of LtsRquestVo objects |
LTS configuration. |
|
workspace_id |
Yes |
String |
Workspace ID. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
accounts |
No |
Array of strings |
Managed account list. This parameter is not required in non-cross-account scenarios. |
|
action |
No |
String |
Operation |
|
alert |
No |
Boolean |
Auto alert conversion. |
|
all_accounts |
No |
Boolean |
Whether to access all managed accounts. |
|
csvc |
No |
String |
Cloud product. |
|
csvc_display |
Yes |
String |
Cloud service description. |
|
enable |
Yes |
Long |
Status. 0: disabled; 1: enabled. |
|
new_account_auto_access |
No |
Boolean |
Whether to automatically synchronize new accounts. |
|
shards |
Yes |
Long |
Number of required partitions. |
|
source_display |
Yes |
String |
Data source description. |
|
source_id |
Yes |
Long |
Data source ID. |
|
source_name |
No |
String |
Log name. |
|
ttl |
Yes |
Long |
Data lifecycle. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
config_name |
No |
String |
Configuration name. |
|
description |
No |
String |
Description. |
|
enable |
No |
String |
Whether to enable. |
|
log_group_id |
No |
String |
Log ID. |
|
log_stream_id |
No |
String |
Log stream ID. |
|
log_type |
No |
String |
Log type. |
|
log_type_prefix |
No |
String |
Log prefix. |
|
pipe_alias |
No |
String |
Log alias. |
Response Parameters
Status code: 200
|
Parameter |
Type |
Description |
|---|---|---|
|
[items] |
Array of ConfigResponse objects |
Response body for saving cloud service collection configurations |
|
Parameter |
Type |
Description |
|---|---|---|
|
alert |
Boolean |
Auto alert conversion. |
|
allow_alert |
Boolean |
Whether to enable auto alert conversion. |
|
allow_lts |
Boolean |
Whether to allow long-term storage. |
|
csvc_display |
String |
Cloud service description. |
|
datasets |
Array of DatasetInfo objects |
Associated dataset list. |
|
region |
Boolean |
Whether to collect data by region. |
|
source_display |
String |
Data source description. |
|
success |
Boolean |
Whether the creation is successful. |
|
total |
Integer |
Number of collected logs. |
|
Parameter |
Type |
Description |
|---|---|---|
|
csvc |
String |
Cloud service to which the data source belongs. For example, enter hss for server security. |
|
enable |
String |
Status. 0: disabled; 1: enabled. |
|
is_region |
Long |
Location information. 1: region; 0: global. |
|
reference |
reference object |
Data source name. |
|
source_id |
Long |
Data source ID. |
|
source_name |
String |
Data source name. |
|
target |
Object |
Destination pipeline information. |
|
type |
Long |
Subscription type. 1: tenant subscription; 2: tenant industry monitoring subscription; 3: platform industry monitoring subscription. Currently, the value is 1. |
|
Parameter |
Type |
Description |
|---|---|---|
|
csvc_display |
String |
Cloud service description. |
|
source_display |
String |
Data source description. |
|
link |
String |
URL. |
|
csvc_help |
String |
Cloud service help. |
|
source_help |
String |
Data source help. |
|
Parameter |
Type |
Description |
|---|---|---|
|
pipe |
String |
Pipeline name. |
|
shards |
Long |
Number of required partitions. |
|
ttl |
Long |
Data lifecycle. |
Example Requests
Save the security log subscription.
{
"domain_id" : "9f284xxxe322",
"workspace_id" : "25a81xxx360c",
"dataspace_name" : "dataspace_a",
"dataspace_id" : "718sxxxgh29",
"config" : [ {
"source_id" : 601,
"enable" : 0,
"alert" : false,
"ttl" : 7,
"shards" : 1,
"csvc_display" : "CTS",
"source_display" : "CTS log",
"csvc" : "cts",
"source_name" : "cts-audit"
} ]
}
Example Responses
Status code: 200
Successful.
[ {
"alert" : false,
"allow_alert" : false,
"allow_lts" : false,
"csvc_display" : "Cloud Trace Service (CTS)",
"datasets" : [ ],
"region" : false,
"source_display" : "CTS logs",
"success" : true,
"total" : 0
} ]
SDK Sample Code
The SDK sample code is as follows.
Save the security log subscription.
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 |
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 CreateCollectConfigSolution { 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(); CreateCollectConfigRequest request = new CreateCollectConfigRequest(); CreateCollectConfigV2RequestBody body = new CreateCollectConfigV2RequestBody(); List<ConfigInfo> listbodyConfig = new ArrayList<>(); listbodyConfig.add( new ConfigInfo() .withAlert(false) .withCsvc("cts") .withCsvcDisplay("Cloud Trace Service (CTS)") .withEnable(0L) .withShards(1L) .withSourceDisplay("CTS logs") .withSourceId(601L) .withSourceName("cts-audit") .withTtl(7L) ); body.withWorkspaceId("25a8188b-db45-4393-b925-1bae8ea4360c"); body.withDomainId("9f284b6b77a247eb9d0ede96e092e322"); body.withConfig(listbodyConfig); request.withBody(body); try { CreateCollectConfigResponse response = client.createCollectConfig(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()); } } } |
Save the security log subscription.
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 |
# 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 = CreateCollectConfigRequest() listConfigbody = [ ConfigInfo( alert=False, csvc="cts", csvc_display="Cloud Trace Service (CTS)", enable=0, shards=1, source_display="CTS logs", source_id=601, source_name="cts-audit", ttl=7 ) ] request.body = CreateCollectConfigV2RequestBody( workspace_id="25a8188b-db45-4393-b925-1bae8ea4360c", domain_id="9f284b6b77a247eb9d0ede96e092e322", config=listConfigbody ) response = client.create_collect_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) |
Save the security log subscription.
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 |
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.CreateCollectConfigRequest{} alertConfig:= false csvcConfig:= "cts" sourceNameConfig:= "cts-audit" var listConfigbody = []model.ConfigInfo{ { Alert: &alertConfig, Csvc: &csvcConfig, CsvcDisplay: "Cloud Trace Service (CTS)", Enable: int64(0), Shards: int64(1), SourceDisplay: "CTS logs", SourceId: int64(601), SourceName: &sourceNameConfig, Ttl: int64(7), }, } domainIdCreateCollectConfigV2RequestBody:= "9f284b6b77a247eb9d0ede96e092e322" request.Body = &model.CreateCollectConfigV2RequestBody{ WorkspaceId: "25a8188b-db45-4393-b925-1bae8ea4360c", DomainId: &domainIdCreateCollectConfigV2RequestBody, Config: listConfigbody, } response, err := client.CreateCollectConfig(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