【问题标题】:logstash configuration grok parse timestamplogstash 配置 grok 解析时间戳
【发布时间】:2017-01-31 12:40:24
【问题描述】:

我正在尝试解析

[7/1/05 13:41:00:516 PDT]

这是我为它编写的配置 grok:

\[%{DD/MM/YY HH:MM:SS:S Z}\]

使用日期过滤器:

input {
file {
path => "logstash-5.0.0/bin/sta.log"
start_position => "beginning"
}
}
filter {
grok {
match =>" \[%{DATA:timestamp}\] "
}
date {
match => ["timestamp","DD/MM/YY HH:MM:SS:S ZZZ"]
}
}
output {
stdout{codec => "json"}
}

以上是我使用的配置。

并将其视为我的 sta.log 文件内容:

[7/1/05 13:41:00:516 PDT]

收到此错误:

[2017-01-31T12:37:47,444][ERROR][logstash.agent           ] fetched an invalid config {:config=>"input {\nfile {\npath => \"logstash-5.0.0/bin/sta.log\"\nstart_position => \"beginning\"\n}\n}\nfilter {\ngrok {\nmatch =>\"\\[%{DATA:timestamp}\\]\"\n}\ndate {\nmatch => [\"timestamp\"=>\"DD/MM/YY HH:MM:SS:S ZZZ\"]\n}\n}\noutput {\nstdout{codec => \"json\"}\n}\n\n", :reason=>"Expected one of #, {, ,, ] at line 12, column 22 (byte 184) after filter {\ngrok {\nmatch =>\"\\[%{DATA:timestamp}\\]\"\n}\ndate {\nmatch => [\"timestamp\""}

有人可以帮忙吗?

【问题讨论】:

    标签: logstash logstash-grok logstash-configuration


    【解决方案1】:

    您忘记为grokfilter 指定输入。正确的配置如下所示:

    input {
      file {
        path => "logstash-5.0.0/bin/sta.log"
        start_position => "beginning"
      }
    }
    
    filter {
      grok {
        match => {"message" => "\[%{DATA:timestamp} PDT\]"}
      }
      date {
        match => ["timestamp","dd/MM/yy HH:mm:ss:SSS"]
      }
    }
    
    output {
      stdout{codec => "json"}
    }
    

    如需进一步参考,请查看grok 文档here

    【讨论】:

    • 但似乎仍然无法使用此配置.. 配置级别有什么问题
    • @SoundaryaThiagarajan 我忘记了大括号。我编辑了我的答案。
    • 获取_dateparsefailure
    • 您的日期字符串也是错误的。我再次编辑了我的答案。
    • 当然.. 你能帮我看看我现在附上的截图吗?我正在尝试这个日志——示例日志:Fri Jul 01 13:44:28 2005
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 2017-07-18
    • 2020-11-10
    • 1970-01-01
    相关资源
    最近更新 更多