无法加载Java类uk.co.jaywayco.Parser

时间:2015-01-30 13:28:21

标签: jar logstash

我正在尝试编写自定义logstash过滤器。我已按照文档here

我的过滤器(分钟)看起来像:

# Call this file 'foo.rb' (in logstash/filters, as above)
require "logstash/filters/base"
require "logstash/namespace"

class LogStash::Filters::NLP < LogStash::Filters::Base

  # Setting the config_name here is required. This is how you
  # configure this filter from your logstash config.
  #
  # filter {
  #   foo { ... }
  # }
  config_name "nlp"

  # New plugins should start life at milestone 1.
  milestone 1

  # Replace the message with this value.
  config :message, :validate => :string

  public
  def register
    # nothing to do
    java_import 'uk.co.jaywayco.Parser'
  end # def register

  public
  def filter(event)
    # return nothing unless there's an actual filter event
    return unless filter?(event)
    if @message
      # Replace the event message with our message as configured in the
      # config file.
      event["message"] = @message
    end
    # filter_matched should go in the last line of our successful code
    filter_matched(event)
  end # def filter
end # class LogStash::Filters::NLP

我创建了一个非常简单的logstash配置,如下所示:

input {
  stdin { type => "nlp" }
}
filter {
  if [type] == "nlp" {
    nlp {
      message => "Hello world! - Youve been NLP'd"
    }
  }
}
output {
  stdout { }
}

当我使用以下命令运行logstash时:

bin/logstash -f /etc/logstash/conf.d/test.conf

我收到以下错误:

The error reported is:
    enter code herecannot load Java class uk.co.jaywayco.Parser

java类uk.co.jaywayco.Parser位于/opt/logstash/lib/logstash/filters文件夹中的jar文件中。这是所有过滤器脚本所在的位置。

为什么不会logstash加载我的java类?

1 个答案:

答案 0 :(得分:0)

好的,感谢logstash IRC频道

解决方案是添加require 'logstash/filters/myjarfile.jar'其他require