简体   繁体   English

Logstash grok失败了

[英]Logstash grok failing

Am trying to grok a message but its failing with _grokparsefailure in log but doesn't actually say what it's failing on. 我试图找到一条消息,但它在日志中没有_grokparsefailure,但实际上并没有说明它失败了。 The grok query works on https://grokdebug.herokuapp.com/ grok查询适用于https://grokdebug.herokuapp.com/

input {
  file {
  type => "apache-access"
  path => "C:/prdLogs/sent/*"
}
   filter {
   grok {
  match => ['message', '%{IP:clientip} - - \[%{GREEDYDATA:raw_timestamp}   \] "%{WORD:httpmethod} %{NOTSPACE:referrer} HTTP/%{NUMBER:httpversion}" %{NUMBER:response} "-" "%{NOTSPACE:request}" %{QS:UserAgent} %{WORD:httpmethodO} - - HTTP/%{NUMBER:httpversion2} "%{WORD:session}:%{WORD:httpmed}" "-" %{NUMBER:duration}' ]
}
   date {
    match => [ "raw_timestamp" , 'dd/MMM/yyyy:HH:mm:ss Z' ]
    target => '@timestamp'
   }
  }

   output {
elasticsearch { hosts => ["111.44.44.44:9200"] }
  }

The data looks like: 数据看起来像:

199.77.22.22 - - [26/Feb/2017:10:18:45 +0800] "GET /myapp/app/i18n/key/parent.selector.label.select.item/?locale=en_GB&dojo.preventCache=1488075524942 HTTP/1.1" 200 "-" "https://mywebsite.here.com:31000/myApp/home.do" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Tablet PC 2.0)" GET - - HTTP/1.1 "0000bKOk4n4SSBHuyJJKed085D6:1ap8u8p8j" "-" 3203
199.77.22.22 - - [26/Feb/2017:10:18:45 +0800] "GET /myapp/app/i18n/key/parent.selector.label.no.recently.used/?locale=en_GB&dojo.preventCache=1488075525483 HTTP/1.1" 200 "-" "https://mywebsite.here.com:31000/myApp/home.do" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Tablet PC 2.0)" GET - - HTTP/1.1 "0000bKOk4n4SSBHuyJJKed085D6:1ap8u8p8j" "-" 3159
199.77.22.22 - - [26/Feb/2017:10:18:46 +0800] "GET /myapp/app/i18n/key/selector.label.selected/?locale=en_GB&dojo.preventCache=1488075525843 HTTP/1.1" 200 "-" "https://mywebsite.here.com:31000/myApp/home.do" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Tablet PC 2.0)" GET - - HTTP/1.1 "0000bKOk4n4SSBHuyJJKed085D6:1ap8u8p8j" "-" 3600
199.77.22.22 - - [26/Feb/2017:10:18:46 +0800] "GET /myapp/app/i18n/key/actor.selector.label.remove.all/?locale=en_GB&dojo.preventCache=1488075526305 HTTP/1.1" 200 "-" "https://mywebsite.here.com:31000/myApp/home.do" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Tablet PC 2.0)" GET - - HTTP/1.1 "0000bKOk4n4SSBHuyJJKed085D6:1ap8u8p8j" "-" 3224
199.77.22.22 - - [26/Feb/2017:10:18:46 +0800] "GET /myapp/app/i18n/key/com.label.filter.objects/?locale=en_GB&dojo.preventCache=1488075526711 HTTP/1.1" 200 "-" "https://mywebsite.here.com:31000/myApp/home.do" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; Tablet PC 2.0)" GET - - HTTP/1.1 "0000bKOk4n4SSBHuyJJKed085D6:1ap8u8p8j" "-" 3299

This is actually an apache access log but I was unable to use COMBINEDAPACHELOG or COMMONAPACHELOG. 这实际上是一个apache访问日志,但我无法使用COMBINEDAPACHELOG或COMMONAPACHELOG。 Same error actually!! 实际上是同样的错

All entries in elasticsearch are tagged as "_grokparsefailure". elasticsearch中的所有条目都标记为“_grokparsefailure”。 I ran logstash in debug mode with log.level at debug but am not seeing any errors in the log. 我在调试模式下使用log.level运行logstash但是在日志中没有看到任何错误。

Am using the latest version of logstash. 我使用的是最新版本的logstash。

Please advise. 请指教。

R2 D2 Thanks, I tried this but no joy :( R2 D2谢谢,我试过这个但没有快乐:(

I created a patterns file and pasted your pattern. 我创建了一个模式文件并粘贴了你的模式。 I just changed the payload to just "130.39.22.22 - - [23/Feb/2015:10:18:45 +0800]" and the following was my filter: 我刚刚将有效负载更改为“130.39.22.22 - [23 / Feb / 2015:10:18:45 +0800]”,以下是我的过滤器:

filter {

grok {
      patterns_dir => ["c:/logstashconfig/patterns"]
      match => ['message', '%{IP:clientip} - - /[%{DATE_CUSTOM:timestamp}/]'] 
    }
date {
    match => [ "timestamp" , 'dd/MMM/yyyy:HH:mm:ss Z' ]
    target => '@timestamp'
  }
}

The debug log in logstash: logstash中的调试日志:

{
      "path" => "C:/prdLogs/sent/test",
"@timestamp" => 2017-03-03T00:06:15.269Z,
      "@version" => "1",
      "host" => "hkw20012125",
   "message" => "130.39.22.22 - -     [23/Feb/2015:10:18:45 +0800]\r",
      "type" => "apache-access",
      "tags" => [
    [0]     "_grokparsefailure"
]   
}

Any ideas? 有任何想法吗? Is it the +0800 at the end of the data? 它是数据末尾的+0800吗? Thanks. 谢谢。

When you have to build your own patterns, start from the left side, go slowly, and use the debugger . 当你必须构建自己的模式时,从左侧开始,慢慢地,并使用调试器

If you test this pattern: 如果您测试此模式:

%{IP:clientip} - - \[

it works, but this one: 它有效,但这一个:

%{IP:clientip} - - \[%{GREEDYDATA:raw_timestamp}   \]

doesn't. 没有。 Comparing your pattern to the input shows that there aren't spaces between the timestamp and the close bracket. 将模式与输入进行比较表明时间戳和关闭括号之间没有空格。

Changing this part of the pattern to: 将此部分模式更改为:

%{IP:clientip} - - \[%{GREEDYDATA:raw_timestamp}\]

works. 作品。

I think once you have GREEDYDATA in your pattern, it means to consider rest of your line from the log: 我想一旦你的模式中有GREEDYDATA ,就意味着从日志中考虑你的其余部分:

GREEDYDATA 's pattern looks like: GREEDYDATA的模式如下:

GREEDYDATA .* <-- means to capture the entire line

And your grok match should look something like this if I'm not mistaken: 如果我没有弄错的话,你的grok匹配看起来应该是这样的:

grok {
  match => ['message', '%{IPV4:clientip} - - %{GREEDYDATA:data}']
}

unless you need the values to be extracted separately, the above grok should do the trick for you. 除非您需要单独提取值,否则上面的grok应该为您完成。 And I think the way you're matching the timestamp is wrong. 我认为你匹配timestamp是错误的。 In order to handle your timestamp you need to have the below patterns within your patterns file: 为了处理您的timestamp您需要在模式文件中包含以下模式:

MONTHDAY (?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])
MONTH \b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b
YEAR (?>\d\d){1,2}
TIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9])
DATE_CUSTOM %{MONTHDAY}[/]%{MONTH }[/]%{YEAR}:%{TIME}

And then you could simply use this within your grok match: 然后你可以在你的grok比赛中使用它:

grok {
    match => ['message', '%{IPV4:clientip} - - \[%{DATE_CUSTOM:timestamp} %{GREEDYDATA:data}']
}

Now you'll be able to match the timestamp as: 现在,您将能够将timestamp匹配为:

date {
    match => [ "timestamp" , 'dd/MMM/yyyy:HH:mm:ss Z' ]
    target => '@timestamp'
}

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM