我正在尝试将自定义过滤器添加到Logstash 1.4.2,它作为Debian软件包安装。还安装了contrib插件(http://logstash.net/docs/1.4.2/contrib-plugins)。此过滤器建立与sqlite数据库的连接,为此它使用JDBC sqlite驱动程序:
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
但是,当我尝试启动logstash时,我在日志中收到以下错误:
“无法加载Java类org.sqlite.JDBC”
我试图将contrib插件提供的sqlite-jdbc-3.7.2.jar
文件放在几个位置,但到目前为止,我无法弄清楚自定义插件所需的JAR是正确的,或者它是否是配置问题。
有什么想法吗?
答案 0 :(得分:0)
虽然我找不到使用Logstash 1.4的外部jar的方法,但是我可以通过用已经包含的Sequel替换SQlite JDBC来实现它。
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