创建日志接入
功能介绍
创建日志接入
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/lts/access-config
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方式请参见:获取账号租户ID、项目资源集ID、日志组ID、日志流ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
从IAM服务获取的用户Token,获取方式请参见:获取用户Token |
Content-Type |
是 |
String |
该字段填为:application/json;charset=UTF-8。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
access_config_name |
是 |
String |
日志接入名称。 满足正则表达式:^(?!.)(?!)(?!.*?.$)[\u4e00-\u9fa5a-zA-Z0-9-.]{1,64}$ |
access_config_type |
是 |
String |
日志接入类型。AGENT:ECS接入,K8S_CCE:CCE接入 |
access_config_detail |
是 |
AccessConfigDeatilCreate object |
访问配置详细信息 |
log_info |
是 |
日志信息 |
|
host_group_info |
否 |
主机组信息 |
|
access_config_tag |
否 |
Array of accessConfigTag objects |
标签信息。KEY不能重复,最多20个标签 |
binary_collect |
否 |
Boolean |
二进制采集 |
log_split |
否 |
Boolean |
日志拆分 |
cluster_id |
否 |
String |
集群ID |
incremental_collect |
否 |
Boolean |
是否增量采集 true 为是 false为否(全量采集) |
encoding_format |
否 |
String |
编码格式,支持UTF-8,GDB默认UTF-8 |
processor_type |
否 |
String |
IC结构化解析类型包括 :SINGLE_LINE 单行全文,MULTI_LINE 多行全文,REGEX 单行正则,MULTI_REGEX 多行正则,SPLIT 分隔符,JSON JSON解析,NGINX nginx解析, COMPOSE组合解析 |
demo_log |
否 |
String |
示例日志 |
demo_fields |
否 |
Array of DemoFieldAccess objects |
示例日志解析字段 |
processors |
否 |
Array of Processor objects |
IC结构化解析器 |
application_id |
否 |
String |
ServiceStage应用ID |
environment_id |
否 |
String |
ServiceStage环境ID |
component_id |
否 |
Array of strings |
ServiceStage组件ID |
access_config_type_source |
否 |
String |
日志接入自建软件来源 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
paths |
否 |
Array of strings |
采集路径。
|
black_paths |
否 |
Array of strings |
采集路径黑名单。
|
format |
是 |
AccessConfigFormatCreate object |
日志格式。single与multi必须选择一种。 |
windows_log_info |
否 |
日志接入采集Windows事件日志 |
|
stdout |
否 |
Boolean |
标准输出开关,仅CCE接入类型时使用 |
stderr |
否 |
Boolean |
标准输出开关标准错误开关,仅CCE接入类型时使用 |
pathType |
否 |
String |
CCE接入类型,仅CCE接入类型时使用 |
namespaceRegex |
否 |
String |
K8s Namespace正则匹配,仅CCE接入类型时使用 |
podNameRegex |
否 |
String |
K8s Pod正则匹配,仅CCE接入类型时使用 |
containerNameRegex |
否 |
String |
K8s 容器名称正则匹配,仅CCE接入类型时使用 |
includeLabels |
否 |
Map<String,String> |
容器 Label白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeLabels |
否 |
Map<String,String> |
容器 Label黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
includeEnvs |
否 |
Map<String,String> |
环境变量白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeEnvs |
否 |
Map<String,String> |
环境变量黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logLabels |
否 |
Map<String,String> |
容器 Label日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logEnvs |
否 |
Map<String,String> |
环境变量日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
includeK8sLabels |
否 |
Map<String,String> |
K8s Label白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeK8sLabels |
否 |
Map<String,String> |
K8s Label黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logK8s |
否 |
Map<String,String> |
K8s Label日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
repeat_collect |
否 |
Boolean |
强制重复采集 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
mode |
否 |
String |
单行日志。system:系统时间,wildcard:时间通配符。 |
value |
否 |
String |
日志时间。当mode为”system”,则填入当前时间戳。当mode为"wildcard",则时间通配符:用日志打印时间来标识一条日志数据,通过时间通配符来匹配日志,每条日志的行首显示日志的打印时间;如果日志中的时间格式为:2019-01-01 23:59:59,时间通配符应该填写为:YYYY-MM-DD hh:mm:ss;如果日志中的时间格式为:19-1-1 23:59:59,时间通配符应该填写为:YY-M-D hh:mm:ss |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
mode |
否 |
String |
单行日志。time:日志时间,regular:正则模式。 |
value |
否 |
String |
日志时间。当mode为"regular",则输入正则表达式当mode为"time",则时间通配符:用日志打印时间来标识一条日志数据,通过时间通配符来匹配日志,每条日志的行首显示日志的打印时间;如果日志中的时间格式为:2019-01-01 23:59:59,时间通配符应该填写为:YYYY-MM-DD hh:mm:ss;如果日志中的时间格式为:19-1-1 23:59:59,时间通配符应该填写为:YY-M-D hh:mm:ss |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
categorys |
是 |
Array of strings |
采集Windows事件日志类型。Application:应用系统,System:系统,Security:安全,Setup:启动 |
time_offset |
是 |
AccessConfigTimeOffset object |
日志接入偏移时间 |
event_level |
是 |
Array of strings |
事件等级。information:info,warning:告警,error:错误,critical:关键,verbose:冗长 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
offset |
是 |
Long |
偏移时间。 当"unit"选择"day"时,范围为1~7天。 当"unit"选择"hour"时,范围为1~168小时。 当"unit"选择"sec"时,范围为1~604800秒。 |
unit |
是 |
String |
偏移时间单位。day :天,hour:小时,sec:秒 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
log_group_id |
是 |
String |
日志组ID |
log_stream_id |
是 |
String |
日志流ID |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
type |
否 |
String |
解析器类型 processor_regex 正则解析 processor_split_string 分词符 processor_json json解析器类型 processor_gotime自定义时间类型 processor_filter_regex日志过滤 processor_drop删除字段类型 processor_rename修改字段类型 |
detail |
否 |
Detail object |
解析器配置 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
source_key |
否 |
String |
自定义时间key字段名称 |
regex |
否 |
String |
正则解析正则表达式 单行完全正则,多行完全正则需填此字段 |
keys |
否 |
Array of strings |
字段名称列表 与field_name字段保持一致 |
multi_line_regex |
否 |
String |
首行正则表达式 |
keep_source |
否 |
Boolean |
是否上传原始日志 |
keep_source_if_parse_error |
否 |
Boolean |
是否上传解析失败日志 |
split_sep |
否 |
String |
分隔符 自定义字符最大长度10,自定义字符串最大长度30 |
split_type |
否 |
String |
分隔符类型:char-自定义字符;special_char-不可见字符;string-自定义字符串 |
fields |
否 |
Map<String,String> |
添加的字段列表:<字段名称 : 字段内容> |
drop_keys |
否 |
Array of strings |
删除的字段列表 |
source_keys |
否 |
Array of strings |
字段重命名源字段名称列表 |
dest_keys |
否 |
Array of strings |
字段重命名替换的字段名称列表 |
expand_depth |
否 |
Integer |
json解析深度,默认为1层最大4层 |
expand_connector |
否 |
String |
json解析字段名称连接符 |
source_format |
否 |
String |
自定义时间时间格式 |
source_value |
否 |
String |
自定义时间字段value |
set_time |
否 |
Boolean |
是否开启自定义时间的开关 |
include |
否 |
Map<String,String> |
日志过滤白名单规则 key长度最大为256,value最大长度为128,key不可以重复 |
exclude |
否 |
Map<String,String> |
日志过滤白名单规则 key长度最大为256,value最大长度为128,key不可以重复 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
access_config_id |
String |
日志接入ID |
access_config_name |
String |
日志接入名称 |
access_config_type |
String |
日志接入类型。AGENT:主机接入 |
create_time |
Long |
创建时间 |
access_config_detail |
AccessConfigDeatilCreate object |
日志接入详细信息 |
log_info |
AccessConfigQueryLogInfo object |
日志接入日志详情 |
host_group_info |
AccessConfigHostGroupIdList object |
日志接入主机组ID列表 |
access_config_tag |
Array of accessConfigTag objects |
标签信息。KEY不能重复,最多20个标签 |
log_split |
Boolean |
日志拆分 |
binary_collect |
Boolean |
二进制收集 |
cluster_id |
String |
CCE集群ID |
encoding_format |
String |
编码格式,默认UTF-8 |
incremental_collect |
Boolean |
采集策略:增量/全量 |
processor_type |
String |
IC结构化解析类型 |
demo_log |
String |
示例日志 |
demo_fields |
Array of DemoFieldAccess objects |
示例日志解析字段 |
processors |
Array of Processor objects |
IC结构化解析器 |
application_id |
String |
ServiceStage应用ID |
environment_id |
String |
ServiceStage环境ID |
component_id |
Array of strings |
ServiceStage组件ID |
参数 |
参数类型 |
描述 |
---|---|---|
paths |
Array of strings |
采集路径。
|
black_paths |
Array of strings |
采集路径黑名单。
|
format |
AccessConfigFormatCreate object |
日志格式。single与multi必须选择一种。 |
windows_log_info |
日志接入采集Windows事件日志 |
|
stdout |
Boolean |
标准输出开关,仅CCE接入类型时使用 |
stderr |
Boolean |
标准输出开关标准错误开关,仅CCE接入类型时使用 |
pathType |
String |
CCE接入类型,仅CCE接入类型时使用 |
namespaceRegex |
String |
K8s Namespace正则匹配,仅CCE接入类型时使用 |
podNameRegex |
String |
K8s Pod正则匹配,仅CCE接入类型时使用 |
containerNameRegex |
String |
K8s 容器名称正则匹配,仅CCE接入类型时使用 |
includeLabels |
Map<String,String> |
容器 Label白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeLabels |
Map<String,String> |
容器 Label黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
includeEnvs |
Map<String,String> |
环境变量白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeEnvs |
Map<String,String> |
环境变量黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logLabels |
Map<String,String> |
容器 Label日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logEnvs |
Map<String,String> |
环境变量日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
includeK8sLabels |
Map<String,String> |
K8s Label白名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
excludeK8sLabels |
Map<String,String> |
K8s Label黑名单,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
logK8s |
Map<String,String> |
K8s Label日志标签,最多支持创建30个,keyname不支持重名,仅CCE接入类型时使用 |
repeat_collect |
Boolean |
强制重复采集 |
参数 |
参数类型 |
描述 |
---|---|---|
mode |
String |
单行日志。system:系统时间,wildcard:时间通配符。 |
value |
String |
日志时间。当mode为”system”,则填入当前时间戳。当mode为"wildcard",则时间通配符:用日志打印时间来标识一条日志数据,通过时间通配符来匹配日志,每条日志的行首显示日志的打印时间;如果日志中的时间格式为:2019-01-01 23:59:59,时间通配符应该填写为:YYYY-MM-DD hh:mm:ss;如果日志中的时间格式为:19-1-1 23:59:59,时间通配符应该填写为:YY-M-D hh:mm:ss |
参数 |
参数类型 |
描述 |
---|---|---|
mode |
String |
单行日志。time:日志时间,regular:正则模式。 |
value |
String |
日志时间。当mode为"regular",则输入正则表达式当mode为"time",则时间通配符:用日志打印时间来标识一条日志数据,通过时间通配符来匹配日志,每条日志的行首显示日志的打印时间;如果日志中的时间格式为:2019-01-01 23:59:59,时间通配符应该填写为:YYYY-MM-DD hh:mm:ss;如果日志中的时间格式为:19-1-1 23:59:59,时间通配符应该填写为:YY-M-D hh:mm:ss |
参数 |
参数类型 |
描述 |
---|---|---|
categorys |
Array of strings |
采集Windows事件日志类型。Application:应用系统,System:系统,Security:安全,Setup:启动 |
time_offset |
AccessConfigTimeOffset object |
日志接入偏移时间 |
event_level |
Array of strings |
事件等级。information:info,warning:告警,error:错误,critical:关键,verbose:冗长 |
参数 |
参数类型 |
描述 |
---|---|---|
offset |
Long |
偏移时间。 当"unit"选择"day"时,范围为1~7天。 当"unit"选择"hour"时,范围为1~168小时。 当"unit"选择"sec"时,范围为1~604800秒。 |
unit |
String |
偏移时间单位。day :天,hour:小时,sec:秒 |
参数 |
参数类型 |
描述 |
---|---|---|
log_group_id |
String |
日志组ID |
log_stream_id |
String |
日志流ID |
log_group_name |
String |
日志组名称 |
log_stream_name |
String |
日志流名称 |
参数 |
参数类型 |
描述 |
---|---|---|
type |
String |
解析器类型 processor_regex 正则解析 processor_split_string 分词符 processor_json json解析器类型 processor_gotime自定义时间类型 processor_filter_regex日志过滤 processor_drop删除字段类型 processor_rename修改字段类型 |
detail |
Detail object |
解析器配置 |
参数 |
参数类型 |
描述 |
---|---|---|
source_key |
String |
自定义时间key字段名称 |
regex |
String |
正则解析正则表达式 单行完全正则,多行完全正则需填此字段 |
keys |
Array of strings |
字段名称列表 与field_name字段保持一致 |
multi_line_regex |
String |
首行正则表达式 |
keep_source |
Boolean |
是否上传原始日志 |
keep_source_if_parse_error |
Boolean |
是否上传解析失败日志 |
split_sep |
String |
分隔符 自定义字符最大长度10,自定义字符串最大长度30 |
split_type |
String |
分隔符类型:char-自定义字符;special_char-不可见字符;string-自定义字符串 |
fields |
Map<String,String> |
添加的字段列表:<字段名称 : 字段内容> |
drop_keys |
Array of strings |
删除的字段列表 |
source_keys |
Array of strings |
字段重命名源字段名称列表 |
dest_keys |
Array of strings |
字段重命名替换的字段名称列表 |
expand_depth |
Integer |
json解析深度,默认为1层最大4层 |
expand_connector |
String |
json解析字段名称连接符 |
source_format |
String |
自定义时间时间格式 |
source_value |
String |
自定义时间字段value |
set_time |
Boolean |
是否开启自定义时间的开关 |
include |
Map<String,String> |
日志过滤白名单规则 key长度最大为256,value最大长度为128,key不可以重复 |
exclude |
Map<String,String> |
日志过滤白名单规则 key长度最大为256,value最大长度为128,key不可以重复 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码 |
error_msg |
String |
错误描述 |
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
错误码 |
error_msg |
String |
错误描述 |
请求示例
-
创建日志接入(CCE接入)
POST https://{endpoint}/v3/{project_id}/lts/access-config { "access_config_name" : "myapinew322", "access_config_type" : "K8S_CCE", "access_config_detail" : { "pathType" : "CONTAINER_STDOUT", "stdout" : "true", "stderr" : "false", "format" : { "single" : { "mode" : "system", "value" : "1678969382000" } }, "namespaceRegex" : "default", "podNameRegex" : "abc", "containerNameRegex" : "my", "includeLabels" : { "a" : "1" }, "excludeLabels" : { "b" : "2" }, "logLabels" : { "c" : "3" }, "includeK8sLabels" : { "d" : "4" }, "excludeK8sLabels" : { "e" : "5" }, "logK8s" : { "f" : "6" }, "includeEnvs" : { "g" : "7" }, "excludeEnvs" : { "h" : "8" }, "logEnvs" : { "i" : "9" } }, "log_info" : { "log_group_id" : "9575cb24-290c-478e-a5db-88d6d1dc513b", "log_stream_id" : "3581bee9-8698-476e-a0ba-b0f310ed99cf" }, "host_group_info" : { "host_group_id_list" : [ "12b0bbd1-4eda-456b-a641-647aa66bdeab" ] }, "access_config_tag" : [ { "key" : "my01", "value" : "001" }, { "key" : "my02", "value" : "002" } ], "binary_collect" : "false", "log_split" : "false" }
-
创建日志接入(ECS接入)
POST https://{endpoint}/v3/{project_id}/lts/access-config { "access_config_name" : "Tesxxx", "access_config_type" : "AGENT", "access_config_detail" : { "paths" : [ "/test/xxx", "/texxx" ], "black_paths" : [ "/testxxx", "/tesxxx" ], "format" : { "multi" : { "mode" : "time", "value" : "YYYY-MM-DD hh:mm:ss" } }, "windows_log_info" : { "categorys" : [ "System", "Security", "Setup" ], "event_level" : [ "warning", "error", "critical", "verbose" ], "time_offset" : { "offset" : 111, "unit" : "hour" } } }, "log_info" : { "log_group_id" : "b179326d-c3be-4217-a3d9-xxxx", "log_stream_id" : "020a6fa0-4740-4888-af06-98xxxxxx" }, "host_group_info" : { "host_group_id_list" : [ "4ee44d4f-a72b-40cf-a3c7-1xxxxx" ] }, "access_config_tag" : [ { "key" : "xxx", "value" : "xxx" }, { "key" : "xxx1", "value" : "xxx1" } ] }
响应示例
状态码: 200
创建日志接入请求响应成功
{ "access_config_detail" : { "containerNameRegex" : "container-1", "format" : { "single" : { "mode" : "system", "value" : "1678969382000" } }, "namespaceRegex" : "default", "pathType" : "container_stdout", "paths" : [ ], "podNameRegex" : "mystdout-6d7458d77c-rhjcc", "stderr" : true, "stdout" : true }, "access_config_id" : "03b16999-95cf-453b-9668-7aa1fafa564e", "access_config_name" : "myapinew32Y", "access_config_tag" : [ { "key" : "my01", "value" : "001" }, { "key" : "my02", "value" : "002" } ], "access_config_type" : "K8S_CCE", "binary_collect" : true, "create_time" : 1685626665176, "log_info" : { "log_group_id" : "9575cb24-290c-478e-a5db-88d6d1dc513b", "log_group_name" : "my-group", "log_stream_id" : "eea03c27-e041-4bec-bd03-6afa10a6561a", "log_stream_name" : "lts-topic-cceapi" }, "log_split" : true }
状态码: 400
非法请求 建议根据error_msg直接修改该请求。
{ "error_code" : "LTS.1807", "error_msg" : "Invalid access config name" }
状态码: 500
表明服务端能被请求访问到,但是服务内部出错。
{ "error_code" : "LTS.0010", "error_msg" : "The system encountered an internal error" }
SDK代码示例
SDK代码示例如下。
-
创建日志接入(CCE接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
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; import java.util.Map; import java.util.HashMap; public class CreateAccessConfigSolution { 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(); CreateAccessConfigRequest request = new CreateAccessConfigRequest(); CreateAccessConfigRequestBody body = new CreateAccessConfigRequestBody(); List<AccessConfigTag> listbodyAccessConfigTag = new ArrayList<>(); listbodyAccessConfigTag.add( new AccessConfigTag() .withKey("my01") .withValue("001") ); listbodyAccessConfigTag.add( new AccessConfigTag() .withKey("my02") .withValue("002") ); List<String> listHostGroupInfoHostGroupIdList = new ArrayList<>(); listHostGroupInfoHostGroupIdList.add("12b0bbd1-4eda-456b-a641-647aa66bdeab"); AccessConfigHostGroupIdListCreate hostGroupInfobody = new AccessConfigHostGroupIdListCreate(); hostGroupInfobody.withHostGroupIdList(listHostGroupInfoHostGroupIdList); AccessConfigBaseLogInfoCreate logInfobody = new AccessConfigBaseLogInfoCreate(); logInfobody.withLogGroupId("9575cb24-290c-478e-a5db-88d6d1dc513b") .withLogStreamId("3581bee9-8698-476e-a0ba-b0f310ed99cf"); Map<String, String> listAccessConfigDetailLogK8s = new HashMap<>(); listAccessConfigDetailLogK8s.put("f", "6"); Map<String, String> listAccessConfigDetailExcludeK8sLabels = new HashMap<>(); listAccessConfigDetailExcludeK8sLabels.put("e", "5"); Map<String, String> listAccessConfigDetailIncludeK8sLabels = new HashMap<>(); listAccessConfigDetailIncludeK8sLabels.put("d", "4"); Map<String, String> listAccessConfigDetailLogEnvs = new HashMap<>(); listAccessConfigDetailLogEnvs.put("i", "9"); Map<String, String> listAccessConfigDetailLogLabels = new HashMap<>(); listAccessConfigDetailLogLabels.put("c", "3"); Map<String, String> listAccessConfigDetailExcludeEnvs = new HashMap<>(); listAccessConfigDetailExcludeEnvs.put("h", "8"); Map<String, String> listAccessConfigDetailIncludeEnvs = new HashMap<>(); listAccessConfigDetailIncludeEnvs.put("g", "7"); Map<String, String> listAccessConfigDetailExcludeLabels = new HashMap<>(); listAccessConfigDetailExcludeLabels.put("b", "2"); Map<String, String> listAccessConfigDetailIncludeLabels = new HashMap<>(); listAccessConfigDetailIncludeLabels.put("a", "1"); AccessConfigFormatSingleCreate singleFormat = new AccessConfigFormatSingleCreate(); singleFormat.withMode(AccessConfigFormatSingleCreate.ModeEnum.fromValue("system")) .withValue("1678969382000"); AccessConfigFormatCreate formatAccessConfigDetail = new AccessConfigFormatCreate(); formatAccessConfigDetail.withSingle(singleFormat); AccessConfigDeatilCreate accessConfigDetailbody = new AccessConfigDeatilCreate(); accessConfigDetailbody.withFormat(formatAccessConfigDetail) .withStdout(true) .withStderr(false) .withPathType(AccessConfigDeatilCreate.PathTypeEnum.fromValue("CONTAINER_STDOUT")) .withNamespaceRegex("default") .withPodNameRegex("abc") .withContainerNameRegex("my") .withIncludeLabels(listAccessConfigDetailIncludeLabels) .withExcludeLabels(listAccessConfigDetailExcludeLabels) .withIncludeEnvs(listAccessConfigDetailIncludeEnvs) .withExcludeEnvs(listAccessConfigDetailExcludeEnvs) .withLogLabels(listAccessConfigDetailLogLabels) .withLogEnvs(listAccessConfigDetailLogEnvs) .withIncludeK8sLabels(listAccessConfigDetailIncludeK8sLabels) .withExcludeK8sLabels(listAccessConfigDetailExcludeK8sLabels) .withLogK8s(listAccessConfigDetailLogK8s); body.withLogSplit(false); body.withBinaryCollect(false); body.withAccessConfigTag(listbodyAccessConfigTag); body.withHostGroupInfo(hostGroupInfobody); body.withLogInfo(logInfobody); body.withAccessConfigDetail(accessConfigDetailbody); body.withAccessConfigType(CreateAccessConfigRequestBody.AccessConfigTypeEnum.fromValue("K8S_CCE")); body.withAccessConfigName("myapinew322"); request.withBody(body); try { CreateAccessConfigResponse response = client.createAccessConfig(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()); } } }
-
创建日志接入(ECS接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
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 CreateAccessConfigSolution { 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(); CreateAccessConfigRequest request = new CreateAccessConfigRequest(); CreateAccessConfigRequestBody body = new CreateAccessConfigRequestBody(); List<AccessConfigTag> listbodyAccessConfigTag = new ArrayList<>(); listbodyAccessConfigTag.add( new AccessConfigTag() .withKey("xxx") .withValue("xxx") ); listbodyAccessConfigTag.add( new AccessConfigTag() .withKey("xxx1") .withValue("xxx1") ); List<String> listHostGroupInfoHostGroupIdList = new ArrayList<>(); listHostGroupInfoHostGroupIdList.add("4ee44d4f-a72b-40cf-a3c7-1xxxxx"); AccessConfigHostGroupIdListCreate hostGroupInfobody = new AccessConfigHostGroupIdListCreate(); hostGroupInfobody.withHostGroupIdList(listHostGroupInfoHostGroupIdList); AccessConfigBaseLogInfoCreate logInfobody = new AccessConfigBaseLogInfoCreate(); logInfobody.withLogGroupId("b179326d-c3be-4217-a3d9-xxxx") .withLogStreamId("020a6fa0-4740-4888-af06-98xxxxxx"); List<AccessConfigWindowsLogInfoCreate.EventLevelEnum> listWindowsLogInfoEventLevel = new ArrayList<>(); listWindowsLogInfoEventLevel.add(AccessConfigWindowsLogInfoCreate.EventLevelEnum.fromValue("warning")); listWindowsLogInfoEventLevel.add(AccessConfigWindowsLogInfoCreate.EventLevelEnum.fromValue("error")); listWindowsLogInfoEventLevel.add(AccessConfigWindowsLogInfoCreate.EventLevelEnum.fromValue("critical")); listWindowsLogInfoEventLevel.add(AccessConfigWindowsLogInfoCreate.EventLevelEnum.fromValue("verbose")); AccessConfigTimeOffset timeOffsetWindowsLogInfo = new AccessConfigTimeOffset(); timeOffsetWindowsLogInfo.withOffset(111L) .withUnit(AccessConfigTimeOffset.UnitEnum.fromValue("hour")); List<AccessConfigWindowsLogInfoCreate.CategorysEnum> listWindowsLogInfoCategorys = new ArrayList<>(); listWindowsLogInfoCategorys.add(AccessConfigWindowsLogInfoCreate.CategorysEnum.fromValue("System")); listWindowsLogInfoCategorys.add(AccessConfigWindowsLogInfoCreate.CategorysEnum.fromValue("Security")); listWindowsLogInfoCategorys.add(AccessConfigWindowsLogInfoCreate.CategorysEnum.fromValue("Setup")); AccessConfigWindowsLogInfoCreate windowsLogInfoAccessConfigDetail = new AccessConfigWindowsLogInfoCreate(); windowsLogInfoAccessConfigDetail.withCategorys(listWindowsLogInfoCategorys) .withTimeOffset(timeOffsetWindowsLogInfo) .withEventLevel(listWindowsLogInfoEventLevel); AccessConfigFormatMutilCreate multiFormat = new AccessConfigFormatMutilCreate(); multiFormat.withMode(AccessConfigFormatMutilCreate.ModeEnum.fromValue("time")) .withValue("YYYY-MM-DD hh:mm:ss"); AccessConfigFormatCreate formatAccessConfigDetail = new AccessConfigFormatCreate(); formatAccessConfigDetail.withMulti(multiFormat); List<String> listAccessConfigDetailBlackPaths = new ArrayList<>(); listAccessConfigDetailBlackPaths.add("/testxxx"); listAccessConfigDetailBlackPaths.add("/tesxxx"); List<String> listAccessConfigDetailPaths = new ArrayList<>(); listAccessConfigDetailPaths.add("/test/xxx"); listAccessConfigDetailPaths.add("/texxx"); AccessConfigDeatilCreate accessConfigDetailbody = new AccessConfigDeatilCreate(); accessConfigDetailbody.withPaths(listAccessConfigDetailPaths) .withBlackPaths(listAccessConfigDetailBlackPaths) .withFormat(formatAccessConfigDetail) .withWindowsLogInfo(windowsLogInfoAccessConfigDetail); body.withAccessConfigTag(listbodyAccessConfigTag); body.withHostGroupInfo(hostGroupInfobody); body.withLogInfo(logInfobody); body.withAccessConfigDetail(accessConfigDetailbody); body.withAccessConfigType(CreateAccessConfigRequestBody.AccessConfigTypeEnum.fromValue("AGENT")); body.withAccessConfigName("Tesxxx"); request.withBody(body); try { CreateAccessConfigResponse response = client.createAccessConfig(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()); } } }
-
创建日志接入(CCE接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
# 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 = CreateAccessConfigRequest() listAccessConfigTagbody = [ AccessConfigTag( key="my01", value="001" ), AccessConfigTag( key="my02", value="002" ) ] listHostGroupIdListHostGroupInfo = [ "12b0bbd1-4eda-456b-a641-647aa66bdeab" ] hostGroupInfobody = AccessConfigHostGroupIdListCreate( host_group_id_list=listHostGroupIdListHostGroupInfo ) logInfobody = AccessConfigBaseLogInfoCreate( log_group_id="9575cb24-290c-478e-a5db-88d6d1dc513b", log_stream_id="3581bee9-8698-476e-a0ba-b0f310ed99cf" ) listLogK8sAccessConfigDetail = { "f": "6" } listExcludeK8sLabelsAccessConfigDetail = { "e": "5" } listIncludeK8sLabelsAccessConfigDetail = { "d": "4" } listLogEnvsAccessConfigDetail = { "i": "9" } listLogLabelsAccessConfigDetail = { "c": "3" } listExcludeEnvsAccessConfigDetail = { "h": "8" } listIncludeEnvsAccessConfigDetail = { "g": "7" } listExcludeLabelsAccessConfigDetail = { "b": "2" } listIncludeLabelsAccessConfigDetail = { "a": "1" } singleFormat = AccessConfigFormatSingleCreate( mode="system", value="1678969382000" ) formatAccessConfigDetail = AccessConfigFormatCreate( single=singleFormat ) accessConfigDetailbody = AccessConfigDeatilCreate( format=formatAccessConfigDetail, stdout=True, stderr=False, path_type="CONTAINER_STDOUT", namespace_regex="default", pod_name_regex="abc", container_name_regex="my", include_labels=listIncludeLabelsAccessConfigDetail, exclude_labels=listExcludeLabelsAccessConfigDetail, include_envs=listIncludeEnvsAccessConfigDetail, exclude_envs=listExcludeEnvsAccessConfigDetail, log_labels=listLogLabelsAccessConfigDetail, log_envs=listLogEnvsAccessConfigDetail, include_k8s_labels=listIncludeK8sLabelsAccessConfigDetail, exclude_k8s_labels=listExcludeK8sLabelsAccessConfigDetail, log_k8s=listLogK8sAccessConfigDetail ) request.body = CreateAccessConfigRequestBody( log_split=False, binary_collect=False, access_config_tag=listAccessConfigTagbody, host_group_info=hostGroupInfobody, log_info=logInfobody, access_config_detail=accessConfigDetailbody, access_config_type="K8S_CCE", access_config_name="myapinew322" ) response = client.create_access_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)
-
创建日志接入(ECS接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
# 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 = CreateAccessConfigRequest() listAccessConfigTagbody = [ AccessConfigTag( key="xxx", value="xxx" ), AccessConfigTag( key="xxx1", value="xxx1" ) ] listHostGroupIdListHostGroupInfo = [ "4ee44d4f-a72b-40cf-a3c7-1xxxxx" ] hostGroupInfobody = AccessConfigHostGroupIdListCreate( host_group_id_list=listHostGroupIdListHostGroupInfo ) logInfobody = AccessConfigBaseLogInfoCreate( log_group_id="b179326d-c3be-4217-a3d9-xxxx", log_stream_id="020a6fa0-4740-4888-af06-98xxxxxx" ) listEventLevelWindowsLogInfo = [ "warning", "error", "critical", "verbose" ] timeOffsetWindowsLogInfo = AccessConfigTimeOffset( offset=111, unit="hour" ) listCategorysWindowsLogInfo = [ "System", "Security", "Setup" ] windowsLogInfoAccessConfigDetail = AccessConfigWindowsLogInfoCreate( categorys=listCategorysWindowsLogInfo, time_offset=timeOffsetWindowsLogInfo, event_level=listEventLevelWindowsLogInfo ) multiFormat = AccessConfigFormatMutilCreate( mode="time", value="YYYY-MM-DD hh:mm:ss" ) formatAccessConfigDetail = AccessConfigFormatCreate( multi=multiFormat ) listBlackPathsAccessConfigDetail = [ "/testxxx", "/tesxxx" ] listPathsAccessConfigDetail = [ "/test/xxx", "/texxx" ] accessConfigDetailbody = AccessConfigDeatilCreate( paths=listPathsAccessConfigDetail, black_paths=listBlackPathsAccessConfigDetail, format=formatAccessConfigDetail, windows_log_info=windowsLogInfoAccessConfigDetail ) request.body = CreateAccessConfigRequestBody( access_config_tag=listAccessConfigTagbody, host_group_info=hostGroupInfobody, log_info=logInfobody, access_config_detail=accessConfigDetailbody, access_config_type="AGENT", access_config_name="Tesxxx" ) response = client.create_access_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)
-
创建日志接入(CCE接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
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.CreateAccessConfigRequest{} keyAccessConfigTag:= "my01" valueAccessConfigTag:= "001" keyAccessConfigTag1:= "my02" valueAccessConfigTag1:= "002" var listAccessConfigTagbody = []model.AccessConfigTag{ { Key: &keyAccessConfigTag, Value: &valueAccessConfigTag, }, { Key: &keyAccessConfigTag1, Value: &valueAccessConfigTag1, }, } var listHostGroupIdListHostGroupInfo = []string{ "12b0bbd1-4eda-456b-a641-647aa66bdeab", } hostGroupInfobody := &model.AccessConfigHostGroupIdListCreate{ HostGroupIdList: listHostGroupIdListHostGroupInfo, } logInfobody := &model.AccessConfigBaseLogInfoCreate{ LogGroupId: "9575cb24-290c-478e-a5db-88d6d1dc513b", LogStreamId: "3581bee9-8698-476e-a0ba-b0f310ed99cf", } var listLogK8sAccessConfigDetail = map[string]string{ "f": "6", } var listExcludeK8sLabelsAccessConfigDetail = map[string]string{ "e": "5", } var listIncludeK8sLabelsAccessConfigDetail = map[string]string{ "d": "4", } var listLogEnvsAccessConfigDetail = map[string]string{ "i": "9", } var listLogLabelsAccessConfigDetail = map[string]string{ "c": "3", } var listExcludeEnvsAccessConfigDetail = map[string]string{ "h": "8", } var listIncludeEnvsAccessConfigDetail = map[string]string{ "g": "7", } var listExcludeLabelsAccessConfigDetail = map[string]string{ "b": "2", } var listIncludeLabelsAccessConfigDetail = map[string]string{ "a": "1", } modeSingle:= model.GetAccessConfigFormatSingleCreateModeEnum().SYSTEM valueSingle:= "1678969382000" singleFormat := &model.AccessConfigFormatSingleCreate{ Mode: &modeSingle, Value: &valueSingle, } formatAccessConfigDetail := &model.AccessConfigFormatCreate{ Single: singleFormat, } stdoutAccessConfigDetail:= true stderrAccessConfigDetail:= false pathTypeAccessConfigDetail:= model.GetAccessConfigDeatilCreatePathTypeEnum().CONTAINER_STDOUT namespaceRegexAccessConfigDetail:= "default" podNameRegexAccessConfigDetail:= "abc" containerNameRegexAccessConfigDetail:= "my" accessConfigDetailbody := &model.AccessConfigDeatilCreate{ Format: formatAccessConfigDetail, Stdout: &stdoutAccessConfigDetail, Stderr: &stderrAccessConfigDetail, PathType: &pathTypeAccessConfigDetail, NamespaceRegex: &namespaceRegexAccessConfigDetail, PodNameRegex: &podNameRegexAccessConfigDetail, ContainerNameRegex: &containerNameRegexAccessConfigDetail, IncludeLabels: listIncludeLabelsAccessConfigDetail, ExcludeLabels: listExcludeLabelsAccessConfigDetail, IncludeEnvs: listIncludeEnvsAccessConfigDetail, ExcludeEnvs: listExcludeEnvsAccessConfigDetail, LogLabels: listLogLabelsAccessConfigDetail, LogEnvs: listLogEnvsAccessConfigDetail, IncludeK8sLabels: listIncludeK8sLabelsAccessConfigDetail, ExcludeK8sLabels: listExcludeK8sLabelsAccessConfigDetail, LogK8s: listLogK8sAccessConfigDetail, } logSplitCreateAccessConfigRequestBody:= false binaryCollectCreateAccessConfigRequestBody:= false request.Body = &model.CreateAccessConfigRequestBody{ LogSplit: &logSplitCreateAccessConfigRequestBody, BinaryCollect: &binaryCollectCreateAccessConfigRequestBody, AccessConfigTag: &listAccessConfigTagbody, HostGroupInfo: hostGroupInfobody, LogInfo: logInfobody, AccessConfigDetail: accessConfigDetailbody, AccessConfigType: model.GetCreateAccessConfigRequestBodyAccessConfigTypeEnum().K8_S_CCE, AccessConfigName: "myapinew322", } response, err := client.CreateAccessConfig(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
创建日志接入(ECS接入)
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
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.CreateAccessConfigRequest{} keyAccessConfigTag:= "xxx" valueAccessConfigTag:= "xxx" keyAccessConfigTag1:= "xxx1" valueAccessConfigTag1:= "xxx1" var listAccessConfigTagbody = []model.AccessConfigTag{ { Key: &keyAccessConfigTag, Value: &valueAccessConfigTag, }, { Key: &keyAccessConfigTag1, Value: &valueAccessConfigTag1, }, } var listHostGroupIdListHostGroupInfo = []string{ "4ee44d4f-a72b-40cf-a3c7-1xxxxx", } hostGroupInfobody := &model.AccessConfigHostGroupIdListCreate{ HostGroupIdList: listHostGroupIdListHostGroupInfo, } logInfobody := &model.AccessConfigBaseLogInfoCreate{ LogGroupId: "b179326d-c3be-4217-a3d9-xxxx", LogStreamId: "020a6fa0-4740-4888-af06-98xxxxxx", } var listEventLevelWindowsLogInfo = []model.AccessConfigWindowsLogInfoCreateEventLevel{ model.GetAccessConfigWindowsLogInfoCreateEventLevelEnum().WARNING, model.GetAccessConfigWindowsLogInfoCreateEventLevelEnum().ERROR, model.GetAccessConfigWindowsLogInfoCreateEventLevelEnum().CRITICAL, model.GetAccessConfigWindowsLogInfoCreateEventLevelEnum().VERBOSE, } timeOffsetWindowsLogInfo := &model.AccessConfigTimeOffset{ Offset: int64(111), Unit: model.GetAccessConfigTimeOffsetUnitEnum().HOUR, } var listCategorysWindowsLogInfo = []model.AccessConfigWindowsLogInfoCreateCategorys{ model.GetAccessConfigWindowsLogInfoCreateCategorysEnum().SYSTEM, model.GetAccessConfigWindowsLogInfoCreateCategorysEnum().SECURITY, model.GetAccessConfigWindowsLogInfoCreateCategorysEnum().SETUP, } windowsLogInfoAccessConfigDetail := &model.AccessConfigWindowsLogInfoCreate{ Categorys: listCategorysWindowsLogInfo, TimeOffset: timeOffsetWindowsLogInfo, EventLevel: listEventLevelWindowsLogInfo, } modeMulti:= model.GetAccessConfigFormatMutilCreateModeEnum().TIME valueMulti:= "YYYY-MM-DD hh:mm:ss" multiFormat := &model.AccessConfigFormatMutilCreate{ Mode: &modeMulti, Value: &valueMulti, } formatAccessConfigDetail := &model.AccessConfigFormatCreate{ Multi: multiFormat, } var listBlackPathsAccessConfigDetail = []string{ "/testxxx", "/tesxxx", } var listPathsAccessConfigDetail = []string{ "/test/xxx", "/texxx", } accessConfigDetailbody := &model.AccessConfigDeatilCreate{ Paths: &listPathsAccessConfigDetail, BlackPaths: &listBlackPathsAccessConfigDetail, Format: formatAccessConfigDetail, WindowsLogInfo: windowsLogInfoAccessConfigDetail, } request.Body = &model.CreateAccessConfigRequestBody{ AccessConfigTag: &listAccessConfigTagbody, HostGroupInfo: hostGroupInfobody, LogInfo: logInfobody, AccessConfigDetail: accessConfigDetailbody, AccessConfigType: model.GetCreateAccessConfigRequestBodyAccessConfigTypeEnum().AGENT, AccessConfigName: "Tesxxx", } response, err := client.CreateAccessConfig(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
创建日志接入请求响应成功 |
400 |
非法请求 建议根据error_msg直接修改该请求。 |
500 |
表明服务端能被请求访问到,但是服务内部出错。 |
错误码
请参见错误码。