10

You know how there is a Ruby filter for Logstash which enables me to write code in Ruby and it is usually included in the config file as follows

filter {
      ruby {
           code => "...."
      }
}

Now I have two Jar files that I would like to include in my filter so that the input I have can be processed according to the operations I have in these Jar files. However, I cannot (apparently) include the Jar file in the ruby code. I've been looking for a solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
hello_its_me
  • 743
  • 2
  • 19
  • 52

2 Answers2

0

So to answer this, I found this wonderful tutorial from Elastc.co:

Shows the steps to create a new gem and use it as a filter for Logstash later on.

https://www.elastic.co/guide/en/logstash/current/_how_to_write_a_logstash_filter_plugin.html

hello_its_me
  • 743
  • 2
  • 19
  • 52
0

Orrr to answer your original question,

you can include a JAR in your ruby code, but you need to be using jruby,

see instructions here on how to access java code from JARs in JRuby:

https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files

To use resources within a jar file from JRuby, the jar file must either be on the classpath or be made available with the require method:

require 'path/to/mycode.jar' This require makes the resources in mycode.jar discoverable by later commands like import and include_package.

Note that loading jar-files via require searches along the $LOAD_PATH for them, like it would for normal ruby files.

bbozo
  • 7,075
  • 3
  • 30
  • 56
  • Yes that is correct and that's how I started with my solution, the gem will be written using Jruby (including the jar file), which will be used as a new logstash filter. thanks :) – hello_its_me Sep 08 '15 at 19:04