Creating a Log Transfer Task (Old Version)
Function
This API is used to transfer logs of one or more specified log streams to Object Storage Service (OBS).
Calling Method
For details, see Calling APIs.
URI
POST /v2/{project_id}/log-dump/obs
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. Default: None 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. Default: None Minimum: 1000 Maximum: 2000 |
Content-Type |
Yes |
String |
Set this parameter to application/json;charset=UTF-8. Default: None Minimum: 30 Maximum: 30 |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
log_group_id |
Yes |
String |
Log group ID. Minimum: 36 Maximum: 36 |
log_stream_ids |
Yes |
Array of strings |
Indicates IDs of log streams whose logs are to be periodically transferred to OBS. You can specify one or more log streams. |
obs_bucket_name |
Yes |
String |
Name of an OBS bucket. Minimum: 3 Maximum: 63 |
type |
Yes |
String |
Set this parameter to cycle, which indicates that the log transfer is periodic. Minimum: 5 Maximum: 5 |
storage_format |
Yes |
String |
Whether the logs are stored in raw or JSON format. The default value is RAW. Minimum length: 3 characters. Maximum length: 4 characters. |
switch_on |
No |
Boolean |
Whether log transfer is enabled. The value is true (default) or false. |
prefix_name |
No |
String |
The file name prefix of the log files transferred to an OBS bucket. Minimum: 0 Maximum: 64 |
dir_prefix_name |
No |
String |
A custom path to store the log files. Minimum: 0 Maximum: 64 |
period |
Yes |
Integer |
Length of the log transfer interval. Enumeration values:
|
period_unit |
Yes |
String |
Unit of the log transfer interval.>The combination of period and period_unit must be one of ["2min","5min","30min","1hour","3hour","6hour","12hour"]. Minimum: 3 Maximum: 4 Enumeration values:
|
Response Parameters
Status code: 201
Parameter |
Type |
Description |
---|---|---|
log_dump_obs_id |
String |
Transfer task ID. Default: None Minimum: 36 Maximum: 36 |
Status code: 400
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. Enumeration values:
|
error_msg |
String |
Error message. Enumeration values:
|
Status code: 403
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. Enumeration values:
|
error_msg |
String |
Error message. Enumeration values:
|
Status code: 500
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code. Enumeration values:
|
error_msg |
String |
Error message. Enumeration values:
|
Example Requests
Creating a log transfer task
POST https://{endpoint}/v2/{project_id}/log-dump/obs { "log_group_id" : "d9dba9f3-xxxx-48bd-xxxx-xxxxa24a8053", "log_stream_ids" : [ "45e7f609-xxxx-4cd3-835b-xxxx4a124718" ], "obs_bucket_name" : "lts-test", "type" : "cycle", "storage_format" : "RAW", "switch_on" : "true", "prefix_name" : "fileprefixname", "dir_prefix_name" : "dirprefixname", "period" : 5, "period_unit" : "min" }
Example Responses
Status code: 200
The request is successful.
The log group does not exist.
{ "error_code" : "LTS.0201", "error_msg" : "The log group does not existed" }
The log stream does not exist.
{ "error_code" : "LTS.0208", "error_msg" : "Log stream id does not exist: 632b9bdc-5afd-4666-a5de-2579f8b80314-" }
The OBS bucket does not exist.
{ "error_code" : "LTS.0416", "error_msg" : "obs bucket does not exist: zhuanchu" }
The log stream ID has been associated during log transfer.
{ "error_code" : "LTS.0207", "error_msg" : "Log stream id is associated by transfer: 632b9bdc-5afd-4666-a5de-2579f8b80314" }
The transfer type is not in the list.
{ "error_code" : "LTS.1901", "error_msg" : "type is not in the list [cycle]" }
The transfer format is not in the list.
{ "error_code" : "LTS.1901", "error_msg" : "storage_format is not in the list [RAW, JSON]" }
The transfer interval is not in the list.
{ "error_code" : "LTS.1901", "error_msg" : "period+period_unit is not in the list [2min, 5min, 30min, 1hour, 3hour, 6hour, 12hour]" }
The transfer unit is not in the list.
{ "error_code" : "LTS.1901", "error_msg" : "period_unit is not in the list [min, hour]" }
The prefix of the transferred log file is invalid. Check the prefix.
{ "error_code" : "LTS.1902", "error_msg" : "prefix_name is invalid, please verify if it's provided as required" }
The prefix of the user-defined transfer path is invalid. Check the prefix.
{ "error_code" : "LTS.1902", "error_msg" : "dir_prefix_name is invalid, please verify if it's provided as required" }
Status code: 201
The request is successful.
{ "log_dump_obs_id" : "45fdc36b-xxxx-4567-xxxx-559xxxxdf968" }
Status code: 400
Bad Request: The request is invalid. Modify the request based on the description in error_msg before a retry.
Bad Request: The request is invalid. Modify the request based on the description in **error_msg** before a retry. { "error_code": "LTS.0007", "error_msg": "The request body format must be json" }
Status code: 403
Forbidden.The request has been rejected.The server has received the request and understood it, but refuses to respond to it. The client should not repeat the request without modifications.
{ "error_code" : "LTS.0001", "error_msg" : "Invalid projectId" }
Status code: 500
InternalServerError. The server has received the request but encountered an internal error.
InternalServerError. The server has received the request but encountered an internal error. { "error_code": "LTS.0010", "error_msg": "Internal Server Error"}
SDK Sample Code
The SDK sample code is as follows.
Creating a log transfer task
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 |
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 CreateLogDumpObsSolution { 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(); CreateLogDumpObsRequest request = new CreateLogDumpObsRequest(); CreateLogDumpObsRequestBody body = new CreateLogDumpObsRequestBody(); List<String> listbodyLogStreamIds = new ArrayList<>(); listbodyLogStreamIds.add("45e7f609-xxxx-4cd3-835b-xxxx4a124718"); body.withPeriodUnit("min"); body.withPeriod(5); body.withDirPrefixName("dirprefixname"); body.withPrefixName("fileprefixname"); body.withSwitchOn(true); body.withStorageFormat("RAW"); body.withType("cycle"); body.withObsBucketName("lts-test"); body.withLogStreamIds(listbodyLogStreamIds); body.withLogGroupId("d9dba9f3-xxxx-48bd-xxxx-xxxxa24a8053"); request.withBody(body); try { CreateLogDumpObsResponse response = client.createLogDumpObs(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 log transfer task
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 |
# 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 = CreateLogDumpObsRequest() listLogStreamIdsbody = [ "45e7f609-xxxx-4cd3-835b-xxxx4a124718" ] request.body = CreateLogDumpObsRequestBody( period_unit="min", period=5, dir_prefix_name="dirprefixname", prefix_name="fileprefixname", switch_on=True, storage_format="RAW", type="cycle", obs_bucket_name="lts-test", log_stream_ids=listLogStreamIdsbody, log_group_id="d9dba9f3-xxxx-48bd-xxxx-xxxxa24a8053" ) response = client.create_log_dump_obs(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 log transfer task
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 |
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.CreateLogDumpObsRequest{} var listLogStreamIdsbody = []string{ "45e7f609-xxxx-4cd3-835b-xxxx4a124718", } dirPrefixNameCreateLogDumpObsRequestBody:= "dirprefixname" prefixNameCreateLogDumpObsRequestBody:= "fileprefixname" switchOnCreateLogDumpObsRequestBody:= true request.Body = &model.CreateLogDumpObsRequestBody{ PeriodUnit: "min", Period: int32(5), DirPrefixName: &dirPrefixNameCreateLogDumpObsRequestBody, PrefixName: &prefixNameCreateLogDumpObsRequestBody, SwitchOn: &switchOnCreateLogDumpObsRequestBody, StorageFormat: "RAW", Type: "cycle", ObsBucketName: "lts-test", LogStreamIds: listLogStreamIdsbody, LogGroupId: "d9dba9f3-xxxx-48bd-xxxx-xxxxa24a8053", } response, err := client.CreateLogDumpObs(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 |
The request is successful. |
201 |
The request is successful. |
400 |
Bad Request: The request is invalid. Modify the request based on the description in error_msg before a retry. |
403 |
Forbidden.The request has been rejected.The server has received the request and understood it, but refuses to respond to it. The client should not repeat the request without modifications. |
500 |
InternalServerError. 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