Updated on 2024-05-22 GMT+08:00

Querying a Tracker

Function

After CTS is enabled, you can view details about the tracker on the Tracker page. The details include the name of the tracker, name of the OBS bucket for storing traces, and prefix of the trace files stored in the OBS bucket.

API Calling

For details, see Calling APIs.

URI

GET /v3/{project_id}/trackers

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details, see Obtaining an Account ID and Project ID.

Table 2 Query parameters

Parameter

Mandatory

Type

Description

tracker_name

No

String

Tracker name. If this parameter is not specified, all trackers of a tenant will be queried.

tracker_type

No

String

Tracker type. The value can be system (management tracker), or data (data tracker).

Enumerated values:

  • system

  • data

Request Parameters

None

Response Parameters

Status code: 200

Table 3 Response body parameters

Parameter

Type

Description

trackers

Array of TrackerResponseBody objects

List of tracker information.

Table 4 TrackerResponseBody

Parameter

Type

Description

id

String

Unique tracker ID.

create_time

Long

Timestamp when the tracker was created.

kms_id

String

Key ID used for transferring and encrypting trace files. This key ID is obtained from Key Management Service (KMS). This parameter is mandatory when tracker_type is set to system and is_support_trace_files_encryption is set to true.

is_support_validate

Boolean

Whether to enable trace file verification.

lts

Lts object

Detail about trace analysis.

tracker_type

String

Tracker type. The value can be system (management tracker), or data (data tracker).

Enumerated values:

  • system

  • data

domain_id

String

Account ID. For details, see section "Obtaining an Account ID and Project ID" in Cloud Trace Service API Reference.

project_id

String

Project ID.

tracker_name

String

Tracker name. The default value is system.

status

String

Tracker status. The value can be enabled, disabled, or error. If the value is set to error, the detail field is required for specifying the source of the error.

Enumerated values:

  • enabled

  • disabled

detail

String

This parameter is returned only when the tracker status is error. It indicates the cause of the abnormal status, and its value can be bucketPolicyError, noBucket, or arrears.

is_support_trace_files_encryption

Boolean

Whether trace files are encrypted during transfer to an OBS bucket. This parameter must be used with kms_id. This function is supported only when the value of tracker_type is system.

obs_info

ObsInfo object

Information about the bucket to which traces are transferred.

data_bucket

DataBucketQuery object

Information about the bucket tracked by a data tracker. This parameter is valid when tracker_type is set to data.

group_id

String

LTS log group ID.

stream_id

String

LTS log stream ID.

is_organization_tracker

Boolean

Whether to apply the tracker configuration to the organization. This parameter is valid only for the management tracker. If the value is set to true, the audit logs of all members in the ORG organization in the current region will be transferred to the OBS bucket or LTS log stream configured for the management tracker. However, audit logs of other members cannot be viewed on the Trace List page.

management_event_selector

ManagementEventSelector object

Management trace selector.

agency_name

String

Name of a cloud service agency.

Table 5 Lts

Parameter

Type

Description

is_lts_enabled

Boolean

Specifies whether to enable the LTS search function.

log_group_name

String

Name of the log group that CTS creates in LTS.

log_topic_name

String

Name of the log topic that CTS creates in LTS.

Table 6 ObsInfo

Parameter

Type

Description

bucket_name

String

OBS bucket name. The value contains 3 to 63 characters and must start with a digit or lowercase letter. Only lowercase letters, digits, hyphens (-), and periods (.) are allowed.

file_prefix_name

String

Prefix of trace files that need to be stored in OBS buckets. The value can contain 0 to 64 characters, including letters, digits, hyphens (-), underscores (_), and periods (.).

is_obs_created

Boolean

Whether the OBS bucket is automatically created by the tracker.

is_authorized_bucket

Boolean

Whether CTS has been granted permissions to perform operations on the OBS bucket.

bucket_lifecycle

Long

Duration that traces are stored in the OBS bucket. This parameter is valid when tracker_type is set to data.

compress_type

String

Compression type. The value can be JSON (no compression) or GZIP (compression). The default format is GZIP.

Enumerated values:

  • gzip

  • json

is_sort_by_service

Boolean

Whether to sort the path by cloud service. If this option is enabled, the cloud service name is added to the transfer file path. The default value is true.

Table 7 DataBucketQuery

Parameter

Type

Description

data_bucket_name

String

OBS bucket name. The value contains 3 to 63 characters and must start with a digit or lowercase letter. Only lowercase letters, digits, hyphens (-), and periods (.) are allowed.

search_enabled

Boolean

Whether the logs of the tracked bucket can be searched.

data_event

Array of strings

Name of the bucket tracked by a data tracker.

  • This parameter is mandatory when the data tracker is enabled or disabled.

  • This parameter is unavailable for a management tracker.

  • Once a tracker is created, the bucket that it tracks cannot be changed.

  • READ OBS: read operations; WRITE OBS: write operations.

Enumerated values:

  • WRITE

  • READ

Table 8 ManagementEventSelector

Parameter

Type

Description

exclude_service

Array of strings

Cloud services whose traces will not be transferred. Currently, the value can only be set to KMS, indicating that the createDatakey traces of KMS will not be transferred.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 403

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 500

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Status code: 503

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Error code. Format: CTS.XXX.

error_msg

String

Error message.

Example Request

GET https://{endpoint}/v3/{project_id}/trackers?tracker_name=system

Example Response

Status code: 200

The request is successful.

{
  "trackers" : [ {
    "is_support_trace_files_encryption" : true,
    "create_time" : 1589886034121,
    "stream_id" : "4a1ef2b6-d79a-4dc6-90f0-48151cd5491b",
    "kms_id" : "7dbbb3fa-93e4-4528-bc7b-9beb794b0229",
    "group_id" : "26fa12ac-75f7-42ed-8118-ab9f2263042f",
    "agency_name" : "cts_admin_trust",
    "is_support_validate" : false,
    "obs_info" : {
      "is_obs_created" : false,
      "bucket_name" : "",
      "is_authorized_bucket" : false,
      "file_prefix_name" : "",
      "bucket_lifecycle" : 0
    },
    "lts" : {
      "log_group_name" : "CTS",
      "is_lts_enabled" : true,
      "log_topic_name" : "system-trace"
    },
    "tracker_type" : "system",
    "domain_id" : "2306579dc99f4c8690b14b68e734fcd9",
    "project_id" : "24edf66e79d04187acb99a463e610764",
    "tracker_name" : "system",
    "id" : "ebf8d1c3-762b-4ce3-b316-6b1aa32f8be3",
    "status" : "enabled"
  }, {
    "domain_id" : "2306579dc99f4c8690b14b68e734fcd9",
    "is_support_trace_files_encryption" : false,
    "obs_info" : {
      "is_obs_created" : false,
      "bucket_name" : "",
      "is_authorized_bucket" : false,
      "file_prefix_name" : "",
      "bucket_lifecycle" : 0
    },
    "create_time" : 1589276171198,
    "project_id" : "24edf66e79d04187acb99a463e610764",
    "data_bucket" : {
      "data_event" : [ "READ", "WRITE" ],
      "search_enabled" : false,
      "data_bucket_name" : "cstest0423"
    },
    "tracker_name" : "sdsa",
    "is_support_validate" : false,
    "lts" : {
      "log_group_name" : "CTS",
      "is_lts_enabled" : false,
      "log_topic_name" : "sdsa"
    },
    "id" : "c9a3961d-3aa0-4e60-8e63-dd4ce7f1a88a",
    "status" : "enabled",
    "tracker_type" : "data"
  } ]
}

Example SDK Code

The example SDK code is as follows.

Java

 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
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.cts.v3.region.CtsRegion;
import com.huaweicloud.sdk.cts.v3.*;
import com.huaweicloud.sdk.cts.v3.model.*;


public class ListTrackersSolution {

    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);

        CtsClient client = CtsClient.newBuilder()
                .withCredential(auth)
                .withRegion(CtsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListTrackersRequest request = new ListTrackersRequest();
        request.withTrackerName("<tracker_name>");
        request.withTrackerType(ListTrackersRequest.TrackerTypeEnum.fromValue("<tracker_type>"));
        try {
            ListTrackersResponse response = client.listTrackers(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());
        }
    }
}

Python

 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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcts.v3.region.cts_region import CtsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcts.v3 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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = CtsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CtsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListTrackersRequest()
        request.tracker_name = "<tracker_name>"
        request.tracker_type = "<tracker_type>"
        response = client.list_trackers(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

 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
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cts/v3/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 := cts.NewCtsClient(
        cts.CtsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListTrackersRequest{}
	trackerNameRequest:= "<tracker_name>"
	request.TrackerName = &trackerNameRequest
	trackerTypeRequest:= model.GetListTrackersRequestTrackerTypeEnum().<TRACKER_TYPE>
	request.TrackerType = &trackerTypeRequest
	response, err := client.ListTrackers(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

More

For SDK sample code in other programming languages, see the Sample Code tab in the API Explorer.

Status Codes

Status Code

Description

200

The request is successful.

400

The server failed to process the request.

401

The request is rejected due to authentication failure.

403

The server understood the request but refused to authorize it.

500

Failed to complete the request because of an internal service error.

503

The requested service is invalid. The client should not repeat the request without modifications.

Error Code

For details, see Error Codes.