如何匹配几种可能的日志事件格式?

时间:2015-01-30 12:51:27

标签: logstash grok logstash-grok

我有来自一个日志源的事件,它可以有几种已知的格式。作为一个例子

10:45 Today is Monday
11:13 The weather is nice
12:00 The weather is cloudy

我可以{/ 1}}通过

每个人match
The weather is %{WORD:weather}
Today is %{WORD:weekday}

我对logstash filter的格式感到不舒服。为了解释这些可能性中的每一种,我应该构建像

这样的东西
if message =~ "The weather is"
{
    grok {
        "match" => "The weather is %{WORD:weather}"
    }
}
if message =~ "Today is"
{
    grok {
    "match" => "Today is %{WORD:weekday}"
    }
}

还是有更紧凑的东西? (例如,具有相关映射的事件的可能模式列表)

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案:枚举模式:

filter {
        grok {
                match =>  { "message" => [ "hello %{WORD:who}", "the weather is %{WORD:weather}" ] }

                }
      }
相关问题