logstash:如何从 log4j 消息中提取数据?

logstash : how to extract data from log4j message?

我尝试使用 logstash 从我的 log4j 消息中提取数据。 消息如下所示:

Method findAll - Start by : bokc

我想提取方法名称:"findAll" 和用户 "bokc"。

我该怎么做?

我使用 logstash 1.5.2,我的配置是:

input {
    log4j {
        mode => "server"
        type => "log4j-artemis"
        port => 4560
    }
}

filter {
  multiline {
    type => "log4j-artemis"
    pattern => "^\s"
    what => "previous"
  }
  mutate {
    add_field => [ "source_ip", "%{host}" ]
  }
}

使用 grok filter:

filter {
  grok {
    match => [
      "message",
      "^Method %{WORD:method} - Start by : %{USER:user}"
    ]
    tag_on_failure => []
  }
}

这会将两个词提取到字段 "method" 和 "user" 中。 tag_on_failure 的设置确保不匹配的邮件不会被标记为 _grokparsefailure。由于大多数消息不应该匹配模式,因此将它们标记为失败没有意义。