I'm trying to add a custom filter to Logstash 1.4.2, which is installed as a Debian package. The contrib plugins (http://logstash.net/docs/1.4.2/contrib-plugins) are also installed. This filter establishes a connection to an sqlite database, and for that it makes use of the JDBC sqlite driver:
require "logstash/filters/base"
require "logstash/namespace"
require "jdbc/sqlite3"
require "java"
class LogStash::Filters::MyFilter < LogStash::Filters::Base
(...)
public
def register
if @database.nil?
raise "You must specify 'database => ...' in your filter"
elsif not File.exists?(@database)
raise "The database does not exist"
end
url = "jdbc:sqlite:" + @database
Java::OrgSqlite::JDBC #initialize the driver
@connection = java.sql.DriverManager.getConnection(url)
@logger.info("Using database", :path => @database)
end # def register
(...)
end # class LogStash::Filters::MyFilter
However, when I try to start logstash I get the following error in the logs :
"cannot load Java class org.sqlite.JDBC"
I've tried to place the sqlite-jdbc-3.7.2.jar
file provided by the contrib plugins into several locations, but so far I couldn't figure out what's the right one for JARs required by custom plugins, or whether it is a configuration issue.
Any ideas?
While I couldn't find the way of using external jars with Logstash 1.4, I could get it to work by replacing SQlite JDBC with Sequel, which is already included.
require "logstash/filters/base"
require "logstash/namespace"
require "sequel"
class LogStash::Filters::MyFilter < LogStash::Filters::Base
(...)
public
def register
if @database.nil?
raise "You must specify 'database => ...' in your filter"
elsif not File.exists?(@database)
raise "The database does not exist"
end
@db = Sequel.connect("jdbc:sqlite:#{@database}")
@logger.info("Using database", :path => @database)
end # def register
(...)
end # class LogStash::Filters::MyFilter