CreateConfig

Last Updated: Sep 15, 2017

Creates log configuration under a project.

Example:

POST /configs

Request syntax

  1. POST /configs HTTP/1.1
  2. Authorization: <AuthorizationString>
  3. Content-Type:application/json
  4. Content-Length:<Content Length>
  5. Content-MD5<:<Content MD5>
  6. Date: <GMT Date>
  7. Host: <Project Endpoint>
  8. x-log-apiversion: 0.6.0
  9. x-log-signaturemethod: hmac-sha1
  10. {
  11. "configName": "testcategory1",
  12. "inputType": "file",
  13. "inputDetail": {
  14. "logType": "common_reg_log",
  15. "logPath": "/var/log/httpd/",
  16. "filePattern": "access*.log",
  17. "localStorage": true,
  18. "timeFormat": "%Y/%m/%d %H:%M:%S",
  19. "logBeginRegex": ".*",
  20. "regex": "(\w+)(\s+)",
  21. "key" :["key1", "key2"],
  22. "filterKey":["key1"],
  23. "filterRegex":["regex1"],
  24. "fileEncoding":"utf8",
  25. "topicFormat": "none"
  26. },
  27. "outputType": "LogService",
  28. "outputDetail":
  29. {
  30. "logstoreName": "perfcounter"
  31. }
  32. }

Request parameters

Attribute Name Type Required or Not Description
configName string Yes The log config name, which is unique in the project.
inputType string Yes The input type, which must be file
inputDetail json Yes See description in the following table.
outputType string Yes The output type, which must be LogService
outputDetail json Yes See the descriptions in the following table.
logSample string No The Logtail log configuration sample. The log size must not exceed 1,000 bytes.

Content of inputDetail:

Attribute Name Type Required or Not Description
logType string Yes The log type. Currently, only common_reg_log is supported.
logPath string Yes The parent directory where the log is located, for example, /var/logs/.
filePattern string Yes The pattern of a log file, for example, access*.log
localStorage boolean Yes Whether to activate local cache. Logs of 1 GB can be stored locally when the links across the servers are disconnected.
timeFormat string Yes The format of log time, for example, %Y/%m/%d %H:%M:%S.
logBeginRegex string Yes The characteristics (regular expression) of the first log line, used for a log composed of multiple lines
regex string Yes The regular expression used for extracting a log pair.
key array Yes The key generated after the log is extracted.
filterKey array Yes The key used for filtering the log. The log meets requirements only when the key value matches the regular expression specified in the corresponding filterRegex column.
filterRegex array Yes The regular expression corresponding to each filterKey. The length of filterRegex must be same as that of filterKey.
topicFormat string No The topic generation mode. Four formats are supported: 1) A part of the log file path is used as the topic, for example, /var/log/(.*).log; 2) none, indicating that the topic is empty; 3) default, indicating that the log file path is used as a topic; 4) group_topic, indicating that the topic attribute of the configured machine group is used as a topic.
preserve boolean No “true” indicates that the monitored directories will never be timed out and “false” indicates that the monitored directories have been timed out by 30 minutes. The default value is true.
preserveDepth integer No If preserve is set to false, the depth of the directories with no monitoring timeout is specified. The maximum depth is 3.
fileEncoding string No Two types are supported: utf8, gbk

Content of outputDetail:

Name Type Required Description
logstoreName string Yes The LogStore name

Request header

No special request header is available. For details about the public request header of the API, refer to Public Request Header.

Response header

No special response header is available. For details about the public response header of the API, refer to Public Response Header.

Response element

The system returns the HTTP status code 200.

Error code

In addition to general error codes of the API, the following special error codes may be returned:

HTTP Status Code Error Code Error Message
400 ConfigAlreadyExist config {Configname} already exist
400 InvalidParameter invalid config resource json
500 InternalServerError internal server error

Detailed description

In case of existing configuration, format error, loss of necessary parameters, or reached quota, creation will fail.

Example

Request example:
  1. POST /configs HTTP/1.1
  2. Header :
  3. {
  4. 'Content-Length': 737,
  5. 'Host': 'ali-test-project.cn-hangzhou-devcommon-intranet.sls.aliyuncs.com',
  6. 'x-log-bodyrawsize': 737,
  7. 'Content-MD5': 'FBA01ECF7255BE143379BC70C56BBF68',
  8. 'x-log-signaturemethod': 'hmac-sha1',
  9. 'Date': 'Mon, 09 Nov 2015 07:45:30 GMT',
  10. 'x-log-apiversion': '0.6.0',
  11. 'User-Agent': 'log-python-sdk-v-0.6.0',
  12. 'Content-Type': 'application/json',
  13. 'Authorization': 'LOG 94to3z418yupi6ikawqqd370:x/L1ymdn9wxe2zrwzcdSG82nXL0='
  14. }
  15. Body:
  16. {
  17. "configName": "sample-logtail-config",
  18. "inputType": "file",
  19. "inputDetail": {
  20. "logType": "common_reg_log",
  21. "logPath": "/var/log/httpd/",
  22. "filePattern": "access*.log",
  23. "localStorage": true,
  24. "timeFormat": "%d/%b/%Y:%H:%M:%S",
  25. "logBeginRegex": "\\d+\\.\\d+\\.\\d+\\.\\d+ - .*",
  26. "regex": "([\\d\\.]+) \\S+ \\S+ \\[(\\S+) \\S+\\] \"(\\w+) ([^\"]*)\" ([\\d\\.]+) (\\d+) (\\d+) (\\d+|-) \"([^\"]*)\" \"([^\"]*)\".*",
  27. "key": ["ip", "time", "method", "url", "request_time", "request_length", "status", "length", "ref_url", "browser"],
  28. "filterKey": [],
  29. "filterRegex": [],
  30. "topicFormat": "none",
  31. "fileEncoding": "utf8"
  32. },
  33. "outputType": "LogService",
  34. "outputDetail":
  35. {
  36. "logstoreName": "sls-test-logstore"
  37. }
  38. }
Response example:
  1. HTTP/1.1 200 OK
  2. Header
  3. {
  4. 'date': 'Mon, 09 Nov 2015 07:45:30 GMT',
  5. 'connection': 'close',
  6. 'x-log-requestid': '56404F1A99248CA26C002180',
  7. 'content-length': '0',
  8. 'server': 'nginx/1.6.1'
  9. }
Thank you! We've received your feedback.