更新时间:2024-05-21 GMT+08:00
分享

查询事件列表

功能介绍

通过事件列表查询接口,可以查出系统记录的7天内资源操作记录。

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/traces

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,参见获取账号ID和项目ID章节。

表2 Query参数

参数

是否必选

参数类型

描述

trace_type

String

标识审计事件类型。 目前支持管理类事件(system)和数据类事件(data)。 默认值为"system"。

枚举值:

  • system
  • data

from

Long

标识查询事件列表的起始时间戳(timestamp,为标准UTC时间,毫秒级,13位数字,不包括传入时间)默认为上一小时的时间戳。查询条件from与to配套使用。

next

String

取值为响应中中marker的值,用于标识查询事件的起始时间(自此条事件的记录时间起,向更早时间查询)。 可以与“from”、“to”结合使用。 最终的查询条件取两组时间条件的交集。

to

Long

标识查询事件列表的结束时间戳(timestamp,为标准UTC时间,毫秒级,13位数字,不包括传入时间)默认为当前时间戳。查询条件to与from配套使用。

tracker_name

String

当"trace_type"字段值为"system"时,该字段值默认为"system"。 当"trace_type"字段值为"data"时,该字段值可以传入数据类追踪器名称,达到筛选某个数据类追踪器下的数据事件目的。

service_type

String

标识查询事件列表对应的云服务类型。必须为已对接CTS的云服务的英文缩写,且服务类型一般为大写字母。 当"trace_type"字段值为"system"时,该字段筛选有效"。 已对接的云服务列表参见《云审计服务用户指南》“支持审计的服务及详细操作列表”章节。

user

String

标识特定用户名称,用以查询该用户下的所有事件。 当"trace_type"字段值为"system"时,该字段筛选有效"。

resource_name

String

标示查询事件列表对应的的资源名称。 当"trace_type"字段值为"system"时,该字段筛选有效"。 说明:该字段可能包含大写字母。

resource_type

String

标示查询事件列表对应的资源类型。 当"trace_type"字段值为"system"时,该字段筛选有效"。

resource_id

String

标示查询事件列表对应的云服务资源ID。 当"trace_type"字段值为"system"时,该字段筛选有效"。

limit

Integer

标示查询事件列表中限定返回的事件条数。不传时默认10条,最大值200条。

trace_id

String

标示某一条事件的事件ID。当传入这个查询条件时,其他查询条件自动不生效。 当"trace_type"字段值为"system"时,该字段筛选有效"。

trace_name

String

标示查询事件列表对应的事件名称。 当"trace_type"字段值为"system"时,该字段筛选有效"。 说明:该字段可能包含大写字母。

trace_rating

String

标示查询事件列表对应的事件等级目前有三种:正常(normal), 警告(warning),事故(incident)。 当"trace_type"字段值为"system"时,该字段筛选有效"。

枚举值:

  • normal
  • warning
  • incident

access_key_id

String

标示查询事件列表对应的访问密钥ID。包含临时访问凭证和永久访问密钥。

enterprise_project_id

String

标示查询事件列表对应的企业项目ID。

请求参数

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

traces

Array of Traces objects

本次查询事件列表返回事件数组。

meta_data

MetaData object

本次查询事件条数和标记位。

表4 Traces

参数

参数类型

描述

resource_id

String

标识事件对应的云服务资源ID。

trace_name

String

标识查询事件列表对应的事件名称。由0-9,a-z,A-Z,'-','.','_',组成,长度为1~64个字符,且以首字符必须为字母。

trace_rating

String

标识事件等级,目前有三种:正常(normal),警告(warning),事故(incident)。

枚举值:

  • normal
  • warning
  • incident

trace_type

String

标识事件发生源头类型,管理类事件主要包括API调用(ApiCall),Console页面调用(ConsoleAction)和系统间调用(SystemAction)。数据类事件主要包括ObsSDK,ObsAPI。

request

String

标识事件对应接口请求内容,即资源操作请求体。

response

String

记录用户请求的响应,标识事件对应接口响应内容,即资源操作结果返回体。

code

String

记录用户请求的响应,标识事件对应接口返回的HTTP状态码。

api_version

String

标识事件对应的云服务接口版本。

message

String

标识其他云服务为此条事件添加的备注信息。

record_time

Long

标识云审计服务记录本次事件的时间戳。

trace_id

String

标识事件的ID,由系统生成的UUID。

time

Long

标识事件产生的时间戳。

user

UserInfo object

标识触发事件的用户信息。

service_type

String

标识查询事件列表对应的云服务类型。必须为已对接CTS的云服务的英文缩写,且服务类型一般为大写字母。

resource_type

String

查询事件列表对应的资源类型。

source_ip

String

标识触发事件的租户IP。

resource_name

String

标识事件对应的资源名称。

request_id

String

记录本次请求的request id

location_info

String

记录本次请求出错后,问题定位所需要的辅助信息。

endpoint

String

云资源的详情页面

resource_url

String

云资源的详情页面的访问链接(不含endpoint)

enterprise_project_id

String

标识资源所在的企业项目ID。

resource_account_id

String

标识资源所在的账号ID。仅在跨租户操作资源时有值。

表5 UserInfo

参数

参数类型

描述

id

String

用户ID,参见《云审计服务API参考》“获取账号ID和项目ID”章节。

name

String

用户名称。

user_name

String

用户名称。

domain

BaseUser object

标识触发事件的用户domain信息。

account_id

String

账号ID,参见《云审计服务API参考》“获取账号ID和项目ID”章节。

access_key_id

String

访问密钥ID。

principal_urn

String

操作用户身份的 URN。

  • 如果是 IAM 用户身份,格式如 iam::<account-id>:user:<user-name>
  • 如果是 IAM 委托会话 身份,格式如 sts::sts::<account-id>:assumed-agency:<agency-name>/<agency-session-name>
  • 如果是 IAM 联邦身份,格式如 sts::<account-id>:external-user:<idp_id>/<user-session-name>

principal_id

String

操作用户身份Id。

  • 如果是 IAM 用户身份,格式为 <user-id>
  • 如果是 IAM 委托会话身份,格式为 <agency-id>:<agency-session-name>
  • 如果是 IAM 联邦身份,格式为 <idp_id>:<user-session-name>

principal_is_root_user

String

是否是根用户。

  • 值为“true”时,表示操作者是根用户。
  • 值为“false”时,表示操作者是委托会话身份、联邦身份或非根用户的 IAM 用户。

枚举值:

  • true
  • false

type

String

操作者身份类型。

invoked_by

Array of strings

发出请求的服务的名称。控制台操作时为["service.console" ]

session_context

SessionContext object

临时安全凭据属性。

表6 BaseUser

参数

参数类型

描述

id

String

账号ID,参见《云审计服务API参考》“获取账号ID和项目ID”章节。

name

String

账号名称。

表7 SessionContext

参数

参数类型

描述

attributes

Attributes object

临时安全凭据的属性。

表8 Attributes

参数

参数类型

描述

created_at

String

颁发临时安全凭证时的时间。

mfa_authenticated

String

是否已经通过MFA身份认证。

表9 MetaData

参数

参数类型

描述

count

Integer

标识本次查询事件列表返回的事件记录的总条数。

marker

String

标识本次查询事件列表返回的最后一个事件ID。可以使用这个参数返回值作为分页请求参数next的值,如果marker返回为null,则表示当前请求条件下查询事件列表已经全部返回没有下一页。

状态码: 400

表10 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 401

表11 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 403

表12 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 404

表13 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 500

表14 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

状态码: 503

表15 响应Body参数

参数

参数类型

描述

error_code

String

错误码标识,CTS.XXX。

error_msg

String

错误描述。

请求示例

  • 查询管理类事件请求样例。
    GET https://{endpoint}/v3/{project_id}/traces?limit=11&to=1479095278000&from=1478490478000&trace_name=createTracker&resource_type=tracker&service_type=CTS&trace_type=system
  • 查询数据类事件请求样例。
    GET https://{endpoint}/v3/{project_id}/traces?limit=11&to=1479095278000&from=1478490478000&trace_type=data

响应示例

状态码: 200

请求正常。

{
  "meta_data" : {
    "count" : 2,
    "marker" : "e001ccb8-bc09-11e6-b2cc-2640a43cc6e8"
  },
  "traces" : [ {
    "time" : 1472148708232,
    "user" : {
      "name" : "xxx",
      "domain" : {
        "name" : "xxx",
        "id" : "ded649d814464428ba89d04d7955c93e"
      }
    },
    "response" : {
      "code" : "VPC.0514",
      "message" : "Update port fail."
    },
    "code" : 200,
    "service_type" : "VPC",
    "resource_type" : "eip",
    "resource_name" : "192.144.163.1",
    "resource_id" : "d502809d-0d1d-41ce-9690-784282142ccc",
    "trace_name" : "deleteEip",
    "trace_rating" : "warning",
    "trace_type" : "ConsoleAction",
    "api_version" : "2.0",
    "record_time" : 1481066128032,
    "trace_id" : "e001ccb9-bc09-11e6-b00b-4b2a61338db6"
  }, {
    "time" : 1472148708232,
    "user" : {
      "name" : "xxx",
      "domain" : {
        "name" : "xxx",
        "id" : "ded649d814464428ba89d04d7955c93e"
      }
    },
    "response" : {
      "code" : "VPC.0514",
      "message" : "Update port fail."
    },
    "code" : 200,
    "service_type" : "VPC",
    "resource_type" : "eip",
    "resource_name" : "192.144.163.1",
    "resource_id" : "d502809d-0d1d-41ce-9690-784282142ccc",
    "trace_name" : "deleteEip",
    "trace_rating" : "warning",
    "trace_type" : "ConsoleAction",
    "api_version" : "2.0",
    "record_time" : 1481066128032,
    "trace_id" : "e001ccb8-bc09-11e6-b2cc-2640a43cc6e8"
  } ]
}

SDK代码示例

SDK代码示例如下。

 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 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 ListTracesSolution {

    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();
        ListTracesRequest request = new ListTracesRequest();
        request.withTraceType(ListTracesRequest.TraceTypeEnum.fromValue("<trace_type>"));
        request.withLimit(<limit>);
        request.withFrom(<from>L);
        request.withNext("<next>");
        request.withTo(<to>L);
        request.withTrackerName("<tracker_name>");
        request.withServiceType("<service_type>");
        request.withUser("<user>");
        request.withResourceId("<resource_id>");
        request.withResourceName("<resource_name>");
        request.withResourceType("<resource_type>");
        request.withTraceId("<trace_id>");
        request.withTraceName("<trace_name>");
        request.withTraceRating(ListTracesRequest.TraceRatingEnum.fromValue("<trace_rating>"));
        try {
            ListTracesResponse response = client.listTraces(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
# 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 = ListTracesRequest()
        request.trace_type = "<trace_type>"
        request.limit = <limit>
        request._from = <from>
        request.next = "<next>"
        request.to = <to>
        request.tracker_name = "<tracker_name>"
        request.service_type = "<service_type>"
        request.user = "<user>"
        request.resource_id = "<resource_id>"
        request.resource_name = "<resource_name>"
        request.resource_type = "<resource_type>"
        request.trace_id = "<trace_id>"
        request.trace_name = "<trace_name>"
        request.trace_rating = "<trace_rating>"
        response = client.list_traces(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
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.ListTracesRequest{}
	request.TraceType = model.GetListTracesRequestTraceTypeEnum().<TRACE_TYPE>
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	fromRequest:= int64(<from>)
	request.From = &fromRequest
	nextRequest:= "<next>"
	request.Next = &nextRequest
	toRequest:= int64(<to>)
	request.To = &toRequest
	trackerNameRequest:= "<tracker_name>"
	request.TrackerName = &trackerNameRequest
	serviceTypeRequest:= "<service_type>"
	request.ServiceType = &serviceTypeRequest
	userRequest:= "<user>"
	request.User = &userRequest
	resourceIdRequest:= "<resource_id>"
	request.ResourceId = &resourceIdRequest
	resourceNameRequest:= "<resource_name>"
	request.ResourceName = &resourceNameRequest
	resourceTypeRequest:= "<resource_type>"
	request.ResourceType = &resourceTypeRequest
	traceIdRequest:= "<trace_id>"
	request.TraceId = &traceIdRequest
	traceNameRequest:= "<trace_name>"
	request.TraceName = &traceNameRequest
	traceRatingRequest:= model.GetListTracesRequestTraceRatingEnum().<TRACE_RATING>
	request.TraceRating = &traceRatingRequest
	response, err := client.ListTraces(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

请求正常。

400

查询参数异常,请求未完成。

401

请求鉴权校验失败,访问被拒绝。

403

请求权限校验失败,访问被禁止。

404

查询事件不存在,请求未完成。

500

服务内部异常,请求未完成。

503

被请求的服务无效。建议直接修改该请求,不要重试该请求。

错误码

请参见错误码

分享:

    相关文档

    相关产品