Trying to build a gem to use it for Logstash as a filter. I'm using classes and methods from a .jar file.
The following is my Jruby code so far:
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require 'java'
require 'Processing.jar'
java_import 'process.Process'
class LogStash::Filters::Process < LogStash::Filters::Base
config_name "process"
StringPath = "/path/to/file/"
ML = JavaUtilities.get_proxy_class('processing.Processing')
@ML = ML.new(StringPath)
public
def register
end
public
def filter(event)
event["result"] = @ML.Process("any string.")
filter_matched(event)
end
end
However, it gave me the following error:
←[31mException in filterworker, the pipeline stopped processing new events, plea
se check your filter configuration and restart Logstash. {"exception"=>#<NoMetho
dError: undefined method 'Process' for nil:NilClass>, "backtrace"=>[
"/path/to/logstash-2.0.0/vendor/local_gems
/dda91dc0/logstash-filter-Process-0.5.0/lib/logstash/filters/processing.rb:54:in 'filter'", "/path/to/log
stash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/f
ilters/base.rb:152:in 'multi_filter'", "org/jruby/RubyArray.java:1613:in 'each'"
, "/path/to/logstash-2.0.0/vendor/bundle/j
ruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base.rb:149:in 'mult
i_filter'", "(eval):233:in 'filter_func'", "/path/to/logstash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/
lib/logstash/pipeline.rb:219:in 'filterworker'", "path/to/log/logstash-2.0.0/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0
-java/lib/logstash/pipeline.rb:154:in 'start_filters'"], :level=>:error}←[0m
NoMethodError: undefined method 'Process' for nil:NilClass
filter at /path/to/logstash-2.0.0
/vendor/local_gems/dda91dc0/logstash-filter-Process-0.5.0/lib/logstash
/filters/Process.rb:54
multi_filter at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base
.rb:152
each at org/jruby/RubyArray.java:1613
multi_filter at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/filters/base
.rb:149
filter_func at (eval):233
filterworker at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/pipeline.rb:
219
start_filters at /path/to/logstash-2.0.0
/vendor/bundle/jruby/1.9/gems/logstash-core-2.0.0-java/lib/logstash/pipeline.rb:
154
I tried the following:
.
.
.
public
def filter(event)
StringPath = "/path/to/file/"
ML = JavaUtilities.get_proxy_class('processing.Processing')
@ML = ML.new(StringPath)
event["result"] = @ML.Process("any string.")
filter_matched(event)
end
end
But it gave me the error:
SyntaxError: dynamic constant assignment error.
I tried this in a normal jruby file and everything worked with me. Using Logstash's filter
however is what seems to be giving me an issue here.