使用logstash处理自定义NGINX日志

时间:2016-05-11 07:54:40

标签: nginx elasticsearch logstash grok

我有nginx访问日志,以json字符串的形式记录请求体。例如。

"{\x0A\x22userId\x22 : \x22MyUserID\x22,\x0A\x22title\x22 : \x22\MyTitle\x0A}" 

我的目标是将这两个值(userId和title)存储到Elastic Search中的2个单独字段中。

我的Logstash配置:

filter {
  if [type] == "nginxlog" {
    grok {
      match => { "message" => "%{COMBINEDAPACHELOG} %{QS:partner_id} %{NUMBER:req_time} %{NUMBER:res_time} %{GREEDYDATA:extra_fields}" }
      add_field => [ "received_at", "%{@timestamp}" ]
      add_field => [ "received_from", "%{host}" ]

    }

   mutate {
    gsub => [
      "extra_fields", x22 ,'"' ,
         "extra_fields",x0A ,'\n'

        ]
    }

    json{
        source => "extra_fields"
        target => "extra_json"

    }

   mutate {
    add_field => {

          "userId => "%{[extra_json][userId]}"
          "title"=> "%{[extra_json][title]}"
        }
 }



   }
}

但是没有正确提取,ES userId = userId中的值,而不是MyUserID。有任何线索问题在哪里?或者任何更好的想法来实现同样的目标?

0 个答案:

没有答案