Class: LogStash::Filters::JdbcMysql
- Inherits:
-
Base
- Object
- Base
- LogStash::Filters::JdbcMysql
- Defined in:
- lib/logstash/filters/jdbc_mysql.rb
Overview
This filter executes a SQL query and store the result set in the field specified as ‘target`.
This filter is a wrapper around the generic jdbc filter for
-
taking care of loading the necessary jdbc driver through a gem depencendy
-
simplified configuration to mysql database.
For example the following configuration:
- source,ruby
-
filter
jdbc_mysql { host => "localhost" default_schema = "mydatabase" user => "me" password => "secret" statement => "select * from WORLD.COUNTRY WHERE Code = :code" parameters => { "code" => "country_code" target => "country_details" }}
is equivalent to the generic configuration
- source,ruby
-
filter {
jdbc { jdbc_driver_library => "/path/to/mysql-connector-java-5.1.34-bin.jar" jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://localhost:3306/mydatabase" jdbc_user => "me" jdbc_password => "secret" statement => "select * from WORLD.COUNTRY WHERE Code = :code" parameters => { "code" => "country_code"} target => "country_details" }}
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
93 94 95 |
# File 'lib/logstash/filters/jdbc_mysql.rb', line 93 def filter(event) @jdbc_filter.filter(event) end |
#register ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/filters/jdbc_mysql.rb', line 77 def register require "jdbc/mysql" Jdbc::MySQL.load_driver @jdbc_filter = LogStash::Filters::Jdbc.new( "jdbc_driver_class" => "com.mysql.jdbc.Driver", "jdbc_connection_string" => "jdbc:mysql://#{host}:#{port}/#{default_schema}", "jdbc_user" => @user, "jdbc_password" => @password.nil? ? nil : @password.value, "statement" => @statement, "parameters" => @parameters, "target" => @target ) @jdbc_filter.register end |