【问题标题】:logstash stopped match a grok second grok filterlogstash 停止匹配 grok 第二个 grok 过滤器
【发布时间】:2014-10-16 06:18:05
【问题描述】:

我有两种来自一个来源的日志消息。我正在尝试使用这样的配置来解析它们:

filter {
  if [type] == "my_type" {
    grok {
      match => [ "message", "field1:" ]
      break_on_match => false
      add_tag => "field1_message"
    }
  }
  if [type] == "my_type" {
    grok {
      match => [ "message", "field2:" ]
      break_on_match => false
      add_tag => "field2_message"
    }
  }
}

Field1 和 Field2 对于每种类型都是唯一的。我的正则表达式和模式是正确的。当我运行这个过滤器时,只有过滤器的第一部分是匹配的,从第二部分开始我只收到 _grokparsefailure。你能帮我解决这个问题吗?

【问题讨论】:

  • 你最后想要完成什么?添加两个标签中的任何一个(在您的示例中为field1_messagefield2_message)还是您的grok 表达式实际上更复杂?

标签: filter match logstash grok


【解决方案1】:

我不知道你的完整配置是什么。对我来说,我已经根据您的要求进行了测试,它对我有用。 以下是我的配置:

input {
    file {
        type => "A"
        path => "/path/to/file/A/server.log.1"
    }
    file {
        type => "B"
        path => "/path/to/file/B/server.log.2"
    }

}

filter{
    if [type] == "A" {
            grok {
                    match => [ "message", "field1: %{WORD:field1}" ]
                    break_on_match => false
                    add_tag => "field1_message"
            }
    }
    if [type] == "B" {
            grok {
                    match => [ "message", "field2: %{WORD:field2}" ]
                    break_on_match => false
                    add_tag => "field2_message"
            }
    }
}

output {
    stdout {
            codec => "rubydebug"
    }
}

这是server.log.1的输入

field1:你好

而对应的输出是

{
   "message" => "field1: hello",
  "@version" => "1",
"@timestamp" => "2014-10-17T03:18:34.421Z",
      "type" => "A",
      "host" => "ABC",
      "path" => "/path/to/file/A/server.log.1",
    "field1" => "hello",
      "tags" => [
    [0] "field1_message"
      ]
}

server.log.2 的第二个输入

field2:世界

输出是

{
   "message" => "field2: world",
  "@version" => "1",
"@timestamp" => "2014-10-17T03:18:33.451Z",
      "type" => "B",
      "host" => "ABC",
      "path" => "/path/to/file/B/server.log.2",
    "field2" => "world",
      "tags" => [
        [0] "field2_message"
    ]
}

希望这对你有帮助,我使用的是 logstash 1.4.1 版。

【讨论】:

    猜你喜欢
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多