UpdateConfig接口用于更新配置内容。如果配置被应用到机器组,则对应机器组也会同时更新。

请求语法

UpdateConfig接口的请求语法如下所示。
PUT /configs/<configName> HTTP/1.1
Authorization: <AuthorizationString> 
Content-Type:application/json
Content-Length:<Content Length>
Content-MD5<:<Content MD5>
Date: <GMT Date>
Host: <Project Endpoint>
x-log-apiversion: 0.6.0
x-log-signaturemethod: hmac-sha1
{
    "configName": "testcategory1",
    "inputType": "file",
    "inputDetail": {
        "logType": "common_reg_log",
        "logPath": "/var/log/httpd/",
        "filePattern": "access.log",
        "localStorage": true,
        "timeFormat": "%Y/%m/%d %H:%M:%S",
        "logBeginRegex": ".*",
        "regex": "(\w+)(\s+)",
        "key" :["key1", "key2"],
        "filterKey":["key1"],
        "filterRegex":["regex1"],
        "topicFormat": "none"
    },
    "outputType": "LogService",
    "outputDetail": 
    {
        "logstoreName": "perfcounter"
    }
}

请求参数

  • 请求头

    UpdateConfig接口无特有请求头。关于Log Service API的公共请求头,请参见公共请求头

  • 请求参数

    请求参数和各种模式的Logtail配置样例,请参见Logtail配置

响应参数

  • 响应头

    UpdateConfig接口无特有响应头。关于Log Service API的公共响应头,请参见公共响应头

  • 响应元素

    成功后返回200状态码。

错误码

除了返回Log Service API的通用错误码,还可能返回如下特有错误码。
HTTP 状态码 ErrorCode ErrorMessage
404 ConfigNotExist config {Configname} does not exist
400 InvalidParameter invalid config resource json
400 BadRequest config resource configname does not match with request
500 InternalServerError internal server error

创建过程中遇到格式错误、必要参数遗失、quota超过限制等,则会创建失败。

示例

  • 请求示例
    PUT /configs/logtail-config-sample
    Header : 
    {
        "Content-Length": 737,
        "Host": "ali-test-project.cn-hangzhou-devcommon-intranet.sls.aliyuncs.com",
        "x-log-bodyrawsize": 737,
        "Content-MD5": "431263EB105D584A5555762A81E869C0",
        "x-log-signaturemethod": "hmac-sha1",
        "Date": "Mon, 09 Nov 2015 09:14:32 GMT",
        "x-log-apiversion": "0.6.0",
        "User-Agent": "log-python-sdk-v-0.6.0",
        "Content-Type": "application/json", 
        "Authorization": "LOG <yourAccessKeyId>:<yourSignature>"
    }
    Body :
    {
        "outputDetail": {
            "logstoreName": "sls-test-logstore"
        }, 
        "inputType": "file", 
        "inputDetail": {
            "regex": "([\\d\\.]+) \\S+ \\S+ \\[(\\S+) \\S+\\] \"(\\w+) ([^\"]*)\" ([\\d\\.]+) (\\d+) (\\d+) (\\d+|-) \"([^\"]*)\" \"([^\"]*)\".*", 
            "filterKey": [], 
            "logPath": "/var/log/nginx/", 
            "logBeginRegex": "\\d+\\.\\d+\\.\\d+\\.\\d+ - .*", 
            "logType": "common_reg_log", 
            "topicFormat": "none", 
            "localStorage": true, 
            "key": [
                "ip", 
                "time", 
                "method", 
                "url", 
                "request_time", 
                "request_length", 
                "status", 
                "length", 
                "ref_url", 
                "browser"
            ], 
            "filePattern": "access*.log", 
            "timeFormat": "%d/%b/%Y:%H:%M:%S",
            "filterRegex": []
        },
        "outputType": "LogService",
        "configName": "logtail-config-sample"
    }
  • 响应示例
    {
        "date": "Mon, 09 Nov 2015 09:14:32 GMT",
        "connection": "close",
        "x-log-requestid": "564063F899248CAA2300B778",
        "content-length": "0",
        "server": "nginx/1.6.1"
    }