简体   繁体   English

特殊日期格式的Logstash日期过滤器

[英]Logstash Date filter on special date format

Im trying to store old log files in elastic and im using logstash for that. 我试图以弹性方式存储旧的日志文件,并为此使用logstash。

time stamps in the logs are of the following format: 日志中的时间戳具有以下格式:

13 AUG 2015 | 07:04:35 | .......

1st problem was the fact the month is in upper case so i copied the "MONTH" pattern as it appears in the grok-patterns and upper-cased all of it: 第一个问题是月份是大写的,所以我复制了出现在grok模式中的“ MONTH”模式并将其全部大写:

original MONTH: 原始MONTH:

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

my upper-case "MONTHCAP": 我的大写字母“ MONTHCAP”:

MONTHCAP \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

next thing i try to do is use the date filter so elastic uses the timestamp from the log as @timestamp filed and NOT the time of the line being stored in elastic: 我尝试做的下一件事是使用日期过滤器,以便Elastic将日志中的时间戳记用作@timestamp字段,而不是将行的时间存储在Elastic中:

date{
                match => ["MONTHDAY","dd","MONTHCAP","MMM","YEAR","yyyy","TIME","HH:mm:ss"]
    }

The problem is that i get the following error trying to store the data: 问题是尝试存储数据时出现以下错误:

Error: Cannot register filter date plugin. The error reported is:
Illegal pattern component: O for pattern 'MONTHCAP'

additional information: this is the grok filter i use to parse the log lines: 附加信息:这是我用来解析日志行的grok过滤器:

%{MONTHDAY} %{MONTHCAP} %{YEAR} \| %{TIME} \|

any idea why i keep getting this error when thr pattern i use is 'MMM' ? 知道为什么我使用的thr模式为'MMM'时会不断收到此错误吗? THanks! 谢谢!

In the documentation the match is only for one field : 在文档中,匹配项仅适用于一个字段:

match => [ "logdate", "MMM dd YYY HH:mm:ss",
      "MMM  d YYY HH:mm:ss", "ISO8601" ]

It takes the first solution which matchs with logdate field. 它采用与logdate字段匹配的第一个解决方案。

You need to construct a field which is your date and after you can do your date filter. 您需要构造一个日期字段,然后才能进行日期过滤。

 match => [logdate, dd MMM yyyy HH:mm:ss]

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

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