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

新建跨账号日志接入

功能介绍

新建跨账号日志接入

调用方法

请参见如何调用API

URI

POST /v2.0/{project_id}/lts/createAgencyAccess

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方式请参见:获取项目ID,获取账号ID,日志组ID、日志流ID

最小长度:1

最大长度:64

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

从IAM服务获取的用户Token,获取方式请参见:获取用户Token

最小长度:1

最大长度:10000

Content-Type

String

该字段填为:application/json;charset=utf8。

最小长度:30

最大长度:30

表3 请求Body参数

参数

是否必选

参数类型

描述

preview_agency_list

Array of PreviewAgencyLogAccessReqBody objects

预览代理列表

表4 PreviewAgencyLogAccessReqBody

参数

是否必选

参数类型

描述

agency_access_type

String

日志访问类型

agency_log_access

String

跨账号日志接入配置名称

log_agencyStream_name

String

委托日志流名称

log_agencyStream_id

String

委托日志流id

log_agencyGroup_name

String

委托日志组名称

log_agencyGroup_id

String

委托日志组id

log_beAgencystream_name

String

被委托日志流名称

log_beAgencystream_id

String

被委托日志流id

log_beAgencygroup_name

String

被委托日志组名称

log_beAgencygroup_id

String

被委托日志组id

be_agency_project_id

String

被委托项目id

agency_project_id

String

委托项目id

agency_domain_name

String

委托账号名称

agency_name

String

委托名称

响应参数

状态码: 201

表5 响应Body参数

参数

参数类型

描述

[数组元素]

Array of LTSAccessConfigInfoRespon200 objects

表6 LTSAccessConfigInfoRespon200

参数

参数类型

描述

access_config_id

String

跨账号日志接入id

project_id

String

项目ID

access_config_name

String

跨账号日志接入名称

access_config_type

Object

跨账号日志接入类型

group_id

String

日志组ID

log_group_name

String

日志组名称

log_stream_id

String

日志流ID

log_stream_name

String

日志流名称

create_time

Long

创建时间

agency_log_access

PreviewAgencyLogAccessReqBody object

委托接入信息

表7 PreviewAgencyLogAccessReqBody

参数

参数类型

描述

agency_access_type

String

日志访问类型

agency_log_access

String

跨账号日志接入配置名称

log_agencyStream_name

String

委托日志流名称

log_agencyStream_id

String

委托日志流id

log_agencyGroup_name

String

委托日志组名称

log_agencyGroup_id

String

委托日志组id

log_beAgencystream_name

String

被委托日志流名称

log_beAgencystream_id

String

被委托日志流id

log_beAgencygroup_name

String

被委托日志组名称

log_beAgencygroup_id

String

被委托日志组id

be_agency_project_id

String

被委托项目id

agency_project_id

String

委托项目id

agency_domain_name

String

委托账号名称

agency_name

String

委托名称

状态码: 400

表8 响应Body参数

参数

参数类型

描述

message

ErrorMessagebody object

错误信息body体

表9 ErrorMessagebody

参数

参数类型

描述

code

String

错误码

最小长度:8

最大长度:36

details

String

错误描述

最小长度:2

最大长度:512

状态码: 500

表10 响应Body参数

参数

参数类型

描述

message

ErrorMessagebody object

错误信息body体

表11 ErrorMessagebody

参数

参数类型

描述

code

String

错误码

最小长度:8

最大长度:36

details

String

错误描述

最小长度:2

最大长度:512

请求示例

新建跨账号日志接入

POST https://{endpoint}//v2.0/{project_id}/lts/createAgencyAccess

{
  "preview_agency_list" : [ {
    "agency_log_access" : "rule_lb30",
    "agency_access_type" : "AGENCYACCESS",
    "agency_name" : "wenshufeng",
    "agency_domain_name" : "paas_aom_z00418070_01",
    "agency_project_id" : "a0a12b069ab4491185d7cf26c3e86ada",
    "be_agency_project_id" : "2a473356cca5487f8373be891bffc1cf",
    "log_agencyStream_name" : "lts-topic-bug",
    "log_agencyStream_id" : "beb169ff-e6e9-4bea-8e77-50afdec74071",
    "log_agencyGroup_name" : "lts-group-sgq",
    "log_agencyGroup_id" : "f06cbfa0-7243-4031-9380-ae0465bd3997",
    "log_beAgencystream_name" : "lts-topic-ECS",
    "log_beAgencystream_id" : "36ce06b0-c6bf-436d-9abe-39de86da28bb",
    "log_beAgencygroup_name" : "lts-group-sgqECS",
    "log_beAgencygroup_id" : "1e749063-d9f5-474f-a537-00cad4e9a108"
  } ]
}

响应示例

状态码: 201

跨账号日志接入成功

[ {
  "access_config_id" : "e929f40e-d1cf-4d59-b656-a2995cbd3229",
  "access_config_name" : "rule_lb30",
  "access_config_type" : "AGENCYACCESS",
  "agency_log_access" : {
    "agency_accessConfig_id" : "e929f40e-d1cf-4d59-b656-a2995cbd3229",
    "agency_access_type" : "AGENCYACCESS",
    "agency_domain_name" : "paas_aom_z00418070_01",
    "agency_log_access" : "rule_lb30",
    "agency_name" : "wenshufeng",
    "agency_project_id" : "a0a12b069ab4491185d7cf26c3e86ada",
    "be_agency_project_id" : "2a473356cca5487f8373be891bffc1cf",
    "log_agencyGroup_id" : "f06cbfa0-7243-4031-9380-ae0465bd3997",
    "log_agencyGroup_name" : "lts-group-sgq",
    "log_agencyStream_id" : "beb169ff-e6e9-4bea-8e77-50afdec74071",
    "log_agencyStream_name" : "lts-topic-bug",
    "log_beAgencygroup_id" : "1e749063-d9f5-474f-a537-00cad4e9a108",
    "log_beAgencygroup_name" : "lts-group-sgqECS",
    "log_beAgencystream_id" : "36ce06b0-c6bf-436d-9abe-39de86da28bb",
    "log_beAgencystream_name" : "lts-topic-ECS"
  },
  "binary_collect" : false,
  "create_time" : 1694400753168,
  "group_id" : "1e749063-d9f5-474f-a537-00cad4e9a108",
  "hostGroupNum" : 0,
  "hostNum" : 0,
  "host_group_info_list" : [ ],
  "host_rule_info" : {
    "black_paths" : [ ],
    "pathType" : "host_file",
    "paths" : [ ],
    "stderr" : false,
    "stdout" : false
  },
  "id" : "",
  "indexId" : "",
  "key" : "",
  "log_group_name" : "lts-group-sgqECS",
  "log_split" : false,
  "log_stream_id" : "36ce06b0-c6bf-436d-9abe-39de86da28bb",
  "log_stream_name" : "lts-topic-ECS",
  "pathNum" : 0,
  "project_id" : "2a473356cca5487f8373be891bffc1cf",
  "tag_list" : [ ]
} ]

状态码: 400

跨账号日志接入创建失败

{
  "message" : {
    "code" : "LTS.0420",
    "details" : "Agency not existed, check domain name and agency name"
  }
}

状态码: 500

服务内部错误

{
  "message" : {
    "code" : "LTS.0010",
    "details" : "The system encountered an internal error"
  }
}

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
60
61
62
63
64
65
66
67
68
69
70
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 CreateAgencyAccessSolution {

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

        LtsClient client = LtsClient.newBuilder()
                .withCredential(auth)
                .withRegion(LtsRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateAgencyAccessRequest request = new CreateAgencyAccessRequest();
        PreviewAgencyLogAccessReqListBody body = new PreviewAgencyLogAccessReqListBody();
        List<PreviewAgencyLogAccessReqBody> listbodyPreviewAgencyList = new ArrayList<>();
        listbodyPreviewAgencyList.add(
            new PreviewAgencyLogAccessReqBody()
                .withAgencyAccessType(PreviewAgencyLogAccessReqBody.AgencyAccessTypeEnum.fromValue("AGENCYACCESS"))
                .withAgencyLogAccess("rule_lb30")
                .withLogAgencyStreamName("lts-topic-bug")
                .withLogAgencyStreamId("beb169ff-e6e9-4bea-8e77-50afdec74071")
                .withLogAgencyGroupName("lts-group-sgq")
                .withLogAgencyGroupId("f06cbfa0-7243-4031-9380-ae0465bd3997")
                .withLogBeAgencystreamName("lts-topic-ECS")
                .withLogBeAgencystreamId("36ce06b0-c6bf-436d-9abe-39de86da28bb")
                .withLogBeAgencygroupName("lts-group-sgqECS")
                .withLogBeAgencygroupId("1e749063-d9f5-474f-a537-00cad4e9a108")
                .withBeAgencyProjectId("2a473356cca5487f8373be891bffc1cf")
                .withAgencyProjectId("a0a12b069ab4491185d7cf26c3e86ada")
                .withAgencyDomainName("paas_aom_z00418070_01")
                .withAgencyName("wenshufeng")
        );
        body.withPreviewAgencyList(listbodyPreviewAgencyList);
        request.withBody(body);
        try {
            CreateAgencyAccessResponse response = client.createAgencyAccess(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
# 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"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

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

    try:
        request = CreateAgencyAccessRequest()
        listPreviewAgencyListbody = [
            PreviewAgencyLogAccessReqBody(
                agency_access_type="AGENCYACCESS",
                agency_log_access="rule_lb30",
                log_agency_stream_name="lts-topic-bug",
                log_agency_stream_id="beb169ff-e6e9-4bea-8e77-50afdec74071",
                log_agency_group_name="lts-group-sgq",
                log_agency_group_id="f06cbfa0-7243-4031-9380-ae0465bd3997",
                log_be_agencystream_name="lts-topic-ECS",
                log_be_agencystream_id="36ce06b0-c6bf-436d-9abe-39de86da28bb",
                log_be_agencygroup_name="lts-group-sgqECS",
                log_be_agencygroup_id="1e749063-d9f5-474f-a537-00cad4e9a108",
                be_agency_project_id="2a473356cca5487f8373be891bffc1cf",
                agency_project_id="a0a12b069ab4491185d7cf26c3e86ada",
                agency_domain_name="paas_aom_z00418070_01",
                agency_name="wenshufeng"
            )
        ]
        request.body = PreviewAgencyLogAccessReqListBody(
            preview_agency_list=listPreviewAgencyListbody
        )
        response = client.create_agency_access(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
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")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := lts.NewLtsClient(
        lts.LtsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateAgencyAccessRequest{}
	var listPreviewAgencyListbody = []model.PreviewAgencyLogAccessReqBody{
        {
            AgencyAccessType: model.GetPreviewAgencyLogAccessReqBodyAgencyAccessTypeEnum().AGENCYACCESS,
            AgencyLogAccess: "rule_lb30",
            LogAgencyStreamName: "lts-topic-bug",
            LogAgencyStreamId: "beb169ff-e6e9-4bea-8e77-50afdec74071",
            LogAgencyGroupName: "lts-group-sgq",
            LogAgencyGroupId: "f06cbfa0-7243-4031-9380-ae0465bd3997",
            LogBeAgencystreamName: "lts-topic-ECS",
            LogBeAgencystreamId: "36ce06b0-c6bf-436d-9abe-39de86da28bb",
            LogBeAgencygroupName: "lts-group-sgqECS",
            LogBeAgencygroupId: "1e749063-d9f5-474f-a537-00cad4e9a108",
            BeAgencyProjectId: "2a473356cca5487f8373be891bffc1cf",
            AgencyProjectId: "a0a12b069ab4491185d7cf26c3e86ada",
            AgencyDomainName: "paas_aom_z00418070_01",
            AgencyName: "wenshufeng",
        },
    }
	request.Body = &model.PreviewAgencyLogAccessReqListBody{
		PreviewAgencyList: listPreviewAgencyListbody,
	}
	response, err := client.CreateAgencyAccess(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

201

跨账号日志接入成功

400

跨账号日志接入创建失败

500

服务内部错误

错误码

请参见错误码

相关文档