【问题标题】:Logstash and elastic search: Split up values within a valueLogstash 和弹性搜索:在一个值中拆分值
【发布时间】:2015-09-14 23:28:19
【问题描述】:

刚刚开始使用 logstash 和弹性搜索

以下是我的日志:

2015-09-09 16:02:23 GET /NeedA/some1/some2/some3/NeedB/some4/NeedC f=json - 127.0.0.1 Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X +10_10_5)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/44.0.2403.157+Safari/537.36 http://localhost:3000/200 373 554 46

使用下面的配置文件,我能够分离出 url: /NeedA/some1/some2/some3/NeedB/some4/NeedC

filter {
  grok {
    match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{WORD:method} %{URIPATH:url} %{NOTSPACE:querystring} %{NOTSPACE:username} %{IPORHOST:ipaddress} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NUMBER:scstatus} %{NUMBER:scbytes:int} %{NUMBER:csbytes:int} %{NUMBER:timetaken:int}"]
  }
  date {
    match => [ "log_timestamp", "YYYY-MM-dd HH:mm:ss" ]
    timezone => "Etc/UCT"
  }
}

问题: 如何从 /NeedA/some1/some2/some3/NeedB/some4/NeedC 中分离出 NeedA、NeedB 和 NeedC 并将其作为弹性搜索中的不同字段

【问题讨论】:

    标签: elasticsearch logstash grok


    【解决方案1】:

    解决办法如下:

    grok {
                    match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{WORD:method} \/%{WORD:fieldA}\/.*\/.*\/.*\/%{WORD:fieldB}\/.*\/%{WORD:fieldC} %{NOTSPACE:querystring} %{NOTSPACE:username} %{IPORHOST:ipaddress} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NUMBER:scstatus} %{NUMBER:scbytes:int} %{NUMBER:csbytes:int} %{NUMBER:timetaken:int}"]
            }
    

    在你的 grok 中,只需将 %{URIPATH:url} 替换为 \/%{WORD:fieldA}\/.*\/.*\/.*\/%{WORD:fieldB}\/.*\/%{WORD:fieldC}

    输出结果:

    {
              "message" => "2015-09-09 16:02:23 GET /NeedA/some1/some2/some3/NeedB/some4/NeedC f=json - 127.0.0.1 Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_10_5)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/44.0.2403.157+Safari/537.36 http://localhost:3000/ 200 373 554 46",
             "@version" => "1",
           "@timestamp" => "2015-09-09T16:02:23.000Z",
                 "host" => "MyHost.local",
                 "path" => "/path/of/test.log",
        "log_timestamp" => "2015-09-09 16:02:23",
               "method" => "GET",
               "fieldA" => "NeedA",
               "fieldB" => "NeedB",
               "fieldC" => "NeedC",
          "querystring" => "f=json",
             "username" => "-",
            "ipaddress" => "127.0.0.1",
            "useragent" => "Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_10_5)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/44.0.2403.157+Safari/537.36",
              "referer" => "http://localhost:3000/",
             "scstatus" => "200",
              "scbytes" => 373,
              "csbytes" => 554,
            "timetaken" => 46
    }
    

    问候, 阿兰

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 2022-12-04
      • 2017-09-13
      相关资源
      最近更新 更多