阅读156 返回首页    go windows


CreateConfig__Logtail配置相关接口_API-Reference_日志服务-阿里云

在Project下创建Config

示例:

POST /configs

请求语法

  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. }

请求参数

属性名称 类型 是否必须 描述
configName string 日志配置名称, Project下唯一
inputType string 输入类型,现在只支持”file”
inputDetail json 见下表格说明
outputType string 输出类型,现在只支持”LogService”
outputDetail json 见下表格说明
logSample string Logtail配置日志样例,最大支持1000字节

inputDetail内容:

属性名称 类型 必须 描述
logType string 日志类型,现在只支持”common_reg_log”
logPath string 日志所在的父目录,例如 /var/logs/
filePattern string 日志文件的Pattern,例如 access*.log
localStorage boolean 是否打开本地缓存,在服务端之间链路断开情况下,本地可以缓存1GB日志
timeFormat string 日志时间格式, 如 “%Y/%m/%d %H:%M:%S”
logBeginRegex string 日志首行特征(正则表达式),由于匹配多行日志组成一条log的情况
regex string 日志对提取正则表达式
key array 日志提取后所生成Key
filterKey array 用于过滤日志所用到的key,只有key的值满足对应filterRegex列中设定的正则表达式日志才是符合要求的
filterRegex array 和每个filterKey对应的正正则表达式, filterRegex的长度和filterKey的长度必须相同
topicFormat string topic生成方式,支持四种类型:1)用于将日志文件路径的某部分作为topic,如/var/log/(.*).log;2)none,表示topic为空;3)default,表示将日志文件路径作为topic;4)group_topic,表示将应用该配置的机器组topic属性作为topic。
preserve boolean true代表监控目录永不超时,false代表监控目录30分钟超时,默认值为true
preserveDepth integer 当设置preserve为false时,指定监控不超时目录的深度,最大深度支持3
fileEncoding string 支持两种类型:”utf8”、”gbk”

outputDetail内容:

属性名称 类型 必须 描述
logstoreName string 对应logstore名字

请求头

无特有请求头,关于API的公共请求头请参考公共请求头

响应头

无特有响应头,关于API的公共响应头请参考公共响应头

响应元素

HTTP状态码返回200

错误码

除了返回API的通用错误码,还可能返回如下特有错误码:

HTTP状态码 ErrorCode ErrorMessage
400 ConfigAlreadyExist config {Configname} already exist
400 InvalidParameter invalid config resource json
500 InternalServerError internal server error

细节描述

创建过程中遇到配置已经存在、格式错误、必要参数遗失、或者quota超过限制等错误,则会创建失败

示例

请求示例:
  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. }
响应示例:
  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. }

最后更新:2016-11-23 16:04:03

  上一篇:go GetAppliedConfigs__Logtail机器组相关接口_API-Reference_日志服务-阿里云
  下一篇:go ListConfig__Logtail配置相关接口_API-Reference_日志服务-阿里云