Create Task CreateTask
Updated at:2025-11-03
Description
Create BLS log collection and transmission tasks
Request
- Request syntax
Text
1POST /task HTTP/1.1
2Host: <Endpoint>
3Authorization: <Authorization String>
4Content-Type: application/json; charset=utf-8
5{
6 "name": <name>,
7 "config": <TaskConfig>,
8 "hosts": List<Host>,
9 "tags": List<Tag>
10}
- Request headers
No additional headers are required beyond the standard request headers.
- Request parameters
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| name | String | Yes | RequestBody | Transmission task name |
| config | TaskConfig | Yes | RequestBody | Task configuration |
| hosts | List<Host> | Yes | RequestBody | List of task running hosts |
| tags | List<Tag> | No | RequestBody | For the tag list to create, see below for specific parameter formats |
- Host
| Parameter name | Types | Description |
|---|---|---|
| hostId | String | Host ID |
- Tag
| Parameter name | Types | Description |
|---|---|---|
| tagKey | String | The key of the tag, which main contain uppercase and lowercase letters, numbers, Chinese characters, and special characters-_ /., with a length of 1-65. |
| tagValue | String | The value of the tag, which main contain uppercase and lowercase letters, numbers, Chinese characters, and special characters-_ /., with a length of 0-65. |
- TaskConfig
| Parameter name | Types | Description |
|---|---|---|
| srcConfig | SrcConfig | Data source location configuration |
| destConfig | DestConfig | Destination location configuration |
- SrcConfig
| Parameter name | Types | Description |
|---|---|---|
| srcType | String | For host type, enter 'host'; for container type, enter 'container'. (Sidecar mode operates in host mode, and therefore enter 'host'.) |
| srcDir | String | Source Log Directory: Use glob mode for matching. For multiple directories, separate them with an English semicolon (;). |
| matchedPattern | String | Source log files, matched by regular expression |
| ignorePattern | String | Ignored source log file |
| timeFormat | String | For BOS delivery, process the source file path and date |
| ttl | Int | Valid log file time range |
| useMultiline | Bool | Whether the multi-line mode is enabled |
| multilineRegex | String | Multi-line mode; the first line in regular expression |
| recursiveDir | Bool | Whether the directory recursion matching is enabled; no directory recursion is added for container collection |
| processType | String | Processing type, options: none (no processing), json (processed by JSON format), separator (processed by separator), regex (processed by regular expression), kv (processed by key value pair) |
| processConfig | ProcessConfig | Detailed configuration of data processing |
| logTime | String | Log time, options: system and logTime, indicating the use of system time and the use of log time respectively |
| timestampKey | String | Specify the processed field to serve as log time |
| dateFormat | String | Specify the time processing format of timestamp field; format shall refer to https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html |
| filterExpr | String | Log matching expression; only logs conforming to the rule are collected |
| additionConfig | JSON | Add collector parameters |
| metaEnv | Collect the list of environment variables | |
| metaLabel | Collect the customized Label list | |
| metaContainer | Collect the fixed container metadata | |
| metaToFields | Write the collected environment variables into the destination location as fields | |
| HarvesterLimit | Int | Number of files collected in parallel by collector, defaulting to 1. When there are many files and a large log volume, it is recommended to use it with the max_procs parameter: https://cloud.baidu.com/doc/BLS/s/ym53rk1ua |
- destConfig
| Parameter name | Types | Description |
|---|---|---|
| destType | String | Destination location type, supporting BLS |
| logStore | String | Logstore name |
| rateLimit | Int | Collection rate limit, unit: MB/second |
| clientCount | Int | Number of clients pushing the server, defaulting to 1. When the log volume is large, the increase of clients will improve data collection speed. |
- ProcessConfig
| Parameter name | Types | Description |
|---|---|---|
| regex | String | If the processing type is regex, fill the regular expression |
| separator | String | If the processing type of separator, specify the separator: “blank”, “comma”, “tab”, “longstring”, “custom” |
| customSeparator | String | When “separator” is “custom”, fill the customized separator here. |
| quote | String | Specify quote characters for separator scenarios, options: blank, double quote ("), single quote ('), and custom |
| kvKeyIndex | Int | Used during KV-based processing, to specify the key group position (start from 1) |
| kvValueIndex | Int | Used during KV-based processing, to specify the value group position (start from 1) |
| sampleLog | Int | Log processing example, used to configure keys and dataType in console after processing |
| keys | String | Column name of processing results |
| dataType | String | Data type corresponding to each column of processing results, supporting string/int/float/bool |
| discardOnFailure | Bool | Whether to discard if log processing fails: true: discard; false: return the original value (for BES delivery, log contents shall be processed with the results delivered in JSON format) |
| keepOriginal | Bool | Whether to retain the original log: true: retain the original log in the @message field of kafka and the @raw field of BLS LogStore; false: not retain the original log upon processing success |
Response
- Response headers
No additional headers are required beyond the standard response headers.
- Response parameters
None
Error code
No other error codes apart from standard error codes.
Example
- Request example
Text
1POST /task HTTP/1.1
2Host: bls-log.bj.baidubce.com
3Authorization:bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
4Content-Type: application/json; charset=utf-8
5
6{
7 "name": "chen_test_bos",
8 "config":{
9 "srcConfig":{
10 "srcType":"host",
11 "srcDir":"/var/log",
12 "matchedPattern":"^.*$",
13 "ignorePattern":"",
14 "ttl":1,
15 "useMultiline": false,
16 "multilineRegex": "\[INFO|ERROR|DEBUG\]",
17 "recursiveDir": false,
18 "processType":"regex",
19 "processConfig": {
20 "regex":"",
21 "separator":"|",
22 "quote":""",
23 "sampleLog": "",
24 "keys":"host,time,log_level,log_content",
25 "dataType":"string,string,string,string",string/int/float/bool
26 "discardOnFailure" : true,
27 "keepOriginal": false
28 "dataType": "string,string,string,string,string,int,string,string,string,string",
29 "kvKeyIndex": 1,
30 "kvValueIndex": 2
31 },
32 "logTime":"system",
33 "timestampKey":"time",
34 "dateFormat":"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z",
35 "filterExpr":"$log_level=\"ERROR|WARN\""
36 },
37 "destConfig":{
38 "destType": "BLS",
39 "logStore": "test1021_3",
40 "rateLimit": 1
41 }
42 },
43 "hosts":[{"hostId":"w4q0q2xwfq5sdi3itcy4k31td43d7e76cd89"}],
44 "tags":[{"tagValue":"tag_value", "tagKey":"tag_key"}]
45}
- Response example
Text
1HTTP/1.1 201
2Content-Type: application/json; charset=utf-8
3X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
4Date: Fri, 10 Apr 2020 04:42:37 GMT
