百度智能云

All Product Document

          Log Service

          Create Task CreateTask

          Description

          Create BLS log collection and transmission tasks

          Request

          • Request syntax
          POST /task HTTP/1.1
          Host: <Endpoint>
          Authorization: <Authorization String>
          Content-Type: application/json; charset=utf-8
          {
            "name": <name>,
            "config": <TaskConfig>,
            "hosts": List<Host>,
            "tags": List<Tag>
          }
          • 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 List Collect the list of environment variables
          metaLabel List Collect the customized Label list
          metaContainer List Collect the fixed container metadata
          metaToFields List 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
          POST /task HTTP/1.1
          Host: bls-log.bj.baidubce.com
          Authorization:bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
          Content-Type: application/json; charset=utf-8
          
          {
              "name": "chen_test_bos",
              "config":{
                  "srcConfig":{
                      "srcType":"host",     
                      "srcDir":"/var/log",
                      "matchedPattern":"^.*$",
                      "ignorePattern":"",
                      "ttl":1,
                      "useMultiline": false,
          			"multilineRegex": "\[INFO|ERROR|DEBUG\]",
          			"recursiveDir": false,
                      "processType":"regex",
                      "processConfig": {
                          "regex":"",
                          "separator":"|",
                          "quote":""",
          				"sampleLog": "",
                          "keys":"host,time,log_level,log_content",
                          "dataType":"string,string,string,string",string/int/float/bool
                          "discardOnFailure" : true,
                          "keepOriginal": false
                           "dataType": "string,string,string,string,string,int,string,string,string,string",
                           "kvKeyIndex": 1,
                           "kvValueIndex": 2
                      },
                      "logTime":"system",
                      "timestampKey":"time",
                      "dateFormat":"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'Z",
                      "filterExpr":"$log_level=\"ERROR|WARN\""
                  },
                  "destConfig":{
          			"destType": "BLS",
          			"logStore": "test1021_3",
          			"rateLimit": 1
                  }
              },
              "hosts":[{"hostId":"w4q0q2xwfq5sdi3itcy4k31td43d7e76cd89"}],
              "tags":[{"tagValue":"tag_value", "tagKey":"tag_key"}]
          }
          • Response example
          HTTP/1.1 201
          Content-Type: application/json; charset=utf-8
          X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
          Date: Fri, 10 Apr 2020 04:42:37 GMT
          Previous
          Log Shipper LogShipper Related Interfaces
          Next
          UpdateTask