有奖:语音产品征文挑战赛火热进行中> HOT

1. 接口描述

接口请求域名: cls.tencentcloudapi.com 。

创建采集规则配置

默认接口请求频率限制:30次/秒。

推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
Action String 公共参数,本接口取值:CreateConfig。
Version String 公共参数,本接口取值:2020-10-16。
Region String 公共参数,详见产品支持的 地域列表
Name String 采集配置名称
示例值:testname
Output String 采集配置所属日志主题ID即TopicId
示例值:xxxxxx-xxx-xxxxxx
Path String 日志采集路径,包含文件名,支持多个路径,多个路径之间英文逗号分隔,文件采集情况下必填
示例值:/data/nginx/log/**/access.log
LogType String 采集的日志类型,默认为minimalist_log。支持以下类型:
- json_log代表:JSON-文件日志(详见使用 JSON 提取模式采集日志);
- delimiter_log代表:分隔符-文件日志(详见使用分隔符提取模式采集日志);
- minimalist_log代表:单行全文-文件日志(详见使用单行全文提取模式采集日志);
- fullregex_log代表:单行完全正则-文件日志(详见使用单行-完全正则提取模式采集日志);
- multiline_log代表:多行全文-文件日志(详见使用多行全文提取模式采集日志);
- multiline_fullregex_log代表:多行完全正则-文件日志(详见使用多行-完全正则提取模式采集日志);
- user_define_log代表:组合解析(适用于多格式嵌套的日志,详见使用组合解析提取模式采集日志);
- service_syslog代表:syslog 采集(详见采集 Syslog);
- windows_event_log代表:Windows事件日志(详见采集 Windows 事件日志)。
示例值:delimiter_log
ExtractRule ExtractRuleInfo 提取规则,如果设置了ExtractRule,则必须设置LogType
ExcludePaths.N Array of ExcludePathInfo 采集黑名单路径列表
UserDefineRule String 用户自定义采集规则,Json格式序列化的字符串。当LogType为user_define_log时,必填。
示例值:"{"processors":[{"type":"processor_split_delimiter","detail":{"Delimiter":",","ExtractKeys":["time","msg1","msg2"]},"processors":[{"type":"processor_timeformat","detail":{"KeepSource":true,"TimeFormat":"%s","SourceKey":"time"}},{"type":"processor_split_delimiter","detail":{"KeepSource":false,"Delimiter":"|","SourceKey":"msg1","ExtractKeys":["submsg1","submsg2","submsg3"]},"processors":[]},{"type":"processor_split_key_value","detail":{"KeepSource":false,"Delimiter":":","SourceKey":"msg2"}}]}]}"
AdvancedConfig String 高级采集配置。 Json字符串, Key/Value定义为如下:
- ClsAgentFileTimeout(超时属性), 取值范围: 大于等于0的整数, 0为不超时
- ClsAgentMaxDepth(最大目录深度),取值范围: 大于等于0的整数
- ClsAgentParseFailMerge(合并解析失败日志),取值范围: true或false
样例:
{\"ClsAgentFileTimeout\":0,\"ClsAgentMaxDepth\":10,\"ClsAgentParseFailMerge\":true}

控制台默认占位值:{\"ClsAgentDefault\":0}
示例值:"{"ClsAgentFileTimeout":0,"ClsAgentMaxDepth":10,"ClsAgentParseFailMerge":true}"

3. 输出参数

参数名称 类型 描述
ConfigId String 采集配置ID
示例值:xxxx-xx-xx-xx-xxxxxxxx
RequestId String 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。

4. 示例

示例1 创建单行全文

FilterKeyRegex:Loglistener日志过滤规则列表(旧版),需要过滤日志的key,及其对应的regex。
注意:2.9.3及以上版本LogListener ,建议使用AdvanceFilterRules配置日志过滤规则。

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateConfig
<公共请求参数>

{
    "Name": "test2.8.8",
    "Path": "/data/log/**/my.log",
    "ExcludePaths": [],
    "LogType": "minimalist_log",
    "UserDefineRule": "",
    "ExtractRule": {
        "IsGBK": 0,
        "FilterKeyRegex": [
            {
                "Key": "__CONTENT__",
                "Regex": "400|500"
            }
        ],
        "Backtracking": 0,
        "MetadataType": 0,
        "MetaTags": [
            {
                "Key": "",
                "Value": ""
            }
        ],
        "PathRegex": ""
    },
    "AdvancedConfig": "{\"ClsAgentFileTimeout\":0}",
    "Output": "6bf3355c-3c88-4566-89c8-76c3ca37bae9"
}

输出示例

{
    "Response": {
        "ConfigId": "a2c6342c-270a-4468-86cf-92625e468888",
        "RequestId": "a21b16c1-4da9-45a1-a612-59e5757384f3"
    }
}

示例2 创建组合解析配置

创建组合解析配置

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateConfig
<公共请求参数>

{
    "Name": "my-test",
    "Path": "/data/log/**/my.log",
    "ExcludePaths": [],
    "LogType": "user_define_log",
    "UserDefineRule": "{\"processors\":[{\"type\":\"processor_split_delimiter\",\"detail\":{\"Delimiter\":\",\",\"ExtractKeys\":[\"time\",\"msg1\",\"msg2\"]},\"processors\":[{\"type\":\"processor_timeformat\",\"detail\":{\"KeepSource\":true,\"TimeFormat\":\"%s\",\"SourceKey\":\"time\"}},{\"type\":\"processor_split_delimiter\",\"detail\":{\"KeepSource\":false,\"Delimiter\":\"|\",\"SourceKey\":\"msg1\",\"ExtractKeys\":[\"submsg1\",\"submsg2\",\"submsg3\"]},\"processors\":[]},{\"type\":\"processor_split_key_value\",\"detail\":{\"KeepSource\":false,\"Delimiter\":\":\",\"SourceKey\":\"msg2\"}}]}]}",
    "ExtractRule": {
        "IsGBK": 0,
        "FilterKeyRegex": [],
        "UnMatchUpLoadSwitch": true,
        "UnMatchLogKey": "LogParseFailure",
        "Backtracking": 0,
        "MetadataType": 2,
        "MetaTags": [
            {
                "Key": "mryx",
                "Value": "item"
            }
        ],
        "PathRegex": ""
    },
    "AdvancedConfig": "{\"ClsAgentFileTimeout\":3600}",
    "Output": "6bf3355c-3c88-4566-89c8-76c3ca37bae9"
}

输出示例

{
    "Response": {
        "ConfigId": "d72dae22-084c-4d20-a81b-f42e25c88888",
        "RequestId": "c708e9af-231e-4a94-a888-3ab24e5fbd97"
    }
}

示例3 创建采集规则配置

创建采集规则配置

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateConfig
<公共请求参数>

{
    "Name": "my-test-minimalist_log",
    "Path": "/data/log/**/my.log",
    "ExcludePaths": [
        {
            "Type": "File",
            "Value": "/data/log/mryx/my.log"
        }
    ],
    "LogType": "minimalist_log",
    "UserDefineRule": "",
    "ExtractRule": {
        "IsGBK": 0,
        "FilterKeyRegex": [],
        "Backtracking": 0,
        "MetadataType": 2,
        "MetaTags": [
            {
                "Key": "mryx",
                "Value": "item"
            },
            {
                "Key": "wd",
                "Value": "shop"
            }
        ],
        "PathRegex": ""
    },
    "AdvancedConfig": "{\"ClsAgentMaxDepth\":10}",
    "Output": "6bf3355c-3c88-4566-89c8-76c3ca37bae9"
}

输出示例

{
    "Response": {
        "ConfigId": "b5a78efe-984c-47e2-99a8-52dbd1388888",
        "RequestId": "037a6def-51d4-449b-a894-7cd2410bfae1"
    }
}

示例4 创建单行完全正则-文件日志

输入示例

POST / HTTP/1.1
Host: cls.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateConfig
<公共请求参数>

{
    "Name": "单行完全正则-文件日志",
    "Path": "/data/log/**/my.log",
    "ExcludePaths": [
        {
            "Type": "File",
            "Value": "/data/log/my.log"
        }
    ],
    "LogType": "fullregex_log",
    "UserDefineRule": "",
    "ExtractRule": {
        "IsGBK": 0,
        "BeginRegex": "\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\",\"\\w+\":\\{\"\\w+\"[^\"]+([^,]+),\"\\w+\":\"/\\w+/\\w+/\\*\\*/\\w+\\.\\w+\",\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"/\\w+/\\w+/\\w+\\.\\w+\"\\}\\],\"\\w+\":\"\\w+\\.\\d+\\.\\d+\",\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\",\"\\w+\":\"\",\"\\w+\":\\{\"\\w+\":\\d+,\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\d+\\|\\d+\"\\}\\],\"\\w+\":\\d+,\"\\w+\":\\d+,\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\"\\}\\],\"\\w+\":\"\",\"\\w+\":\\[\\]\\},\"\\w+\":\"\\{\\\\\"\\w+\\\\\":\\d+\\}\",\"\\w+\"[^\"]+([^\\}]+).*",
        "LogRegex": "\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\",\"\\w+\":\\{\"\\w+\"[^\"]+([^,]+),\"\\w+\":\"/\\w+/\\w+/\\*\\*/\\w+\\.\\w+\",\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"/\\w+/\\w+/\\w+\\.\\w+\"\\}\\],\"\\w+\":\"\\w+\\.\\d+\\.\\d+\",\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\",\"\\w+\":\"\",\"\\w+\":\\{\"\\w+\":\\d+,\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\d+\\|\\d+\"\\}\\],\"\\w+\":\\d+,\"\\w+\":\\d+,\"\\w+\":\\[\\{\"\\w+\":\"\\w+\",\"\\w+\":\"\\w+\"\\}\\],\"\\w+\":\"\",\"\\w+\":\\[\\]\\},\"\\w+\":\"\\{\\\\\"\\w+\\\\\":\\d+\\}\",\"\\w+\"[^\"]+([^\\}]+).*",
        "Keys": [
            "Version",
            "ConfigId"
        ],
        "TimeKey": "log_time",
        "TimeFormat": "%Y-%m-%d %H:%M:%S.%f",
        "FilterKeyRegex": [
            {
                "Key": "key1",
                "Regex": "value1"
            },
            {
                "Key": "key2",
                "Regex": "velue2"
            }
        ],
        "UnMatchUpLoadSwitch": true,
        "UnMatchLogKey": "LogParseFailure",
        "Backtracking": 10,
        "MetadataType": 2,
        "MetaTags": [
            {
                "Key": "mryx",
                "Value": "item"
            }
        ],
        "PathRegex": ""
    },
    "AdvancedConfig": "{\"ClsAgentMaxDepth\":10,\"ClsAgentFileTimeout\":3600}",
    "Output": "6bf3355c-3c88-4566-89c8-76c3ca37bae9"
}

输出示例

{
    "Response": {
        "ConfigId": "8e63fe9a-5f36-49b0-bdbf-ab1c29e58888",
        "RequestId": "420f4f07-2134-4167-9442-9ac6c6ffe3d8"
    }
}

5. 开发者资源

腾讯云 API 平台

腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。

API Inspector

用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。

SDK

云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。

命令行工具

6. 错误码

以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码

错误码 描述
AuthFailure CAM签名/鉴权错误。
FailedOperation 操作失败。
InternalError 内部错误。
InvalidParameter 参数错误。
InvalidParameter.ConfigConflict 相同的采集配置规则已经存在。
InvalidParameterValue 参数取值错误。
LimitExceeded.Config 采集规则配置超过最大值限制。
MissingParameter 缺少参数错误。
OperationDenied 操作被拒绝。
OperationDenied.AccountDestroy 账户已销毁。
OperationDenied.AccountIsolate 账户欠费。
OperationDenied.AccountNotExists 账户不存在。
ResourceNotFound.ConfigNotExist 指定的采集规则配置不存在。
ResourceNotFound.TopicNotExist 日志主题不存在。