閱讀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_日誌服務-阿裏雲