Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Filter: support multiple positional parameters #81

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/logstash/filters/jdbc_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def filter(event)
def close
@scheduler.stop if @scheduler
@parsed_loaders.each(&:close)
@processor.close
@processor.close if @processor
end

def loader_runner
Expand Down
79 changes: 79 additions & 0 deletions spec/filters/integration/jdbc_static_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,85 @@ module LogStash module Filters
end
end

context "under normal conditions with prepared statement with multiple positional parameters" do

let(:event) { LogStash::Event.new("host" => { "ip" => "10.3.1.1", "name" => "mv-server-1"}, "message" => "ping") }
let(:lookup_statement) { "SELECT * FROM servers WHERE ip = ? AND name = ?" }

let(:settings) do
{
"jdbc_user" => ENV['USER'],
"jdbc_password" => ENV["POSTGRES_PASSWORD"],
"jdbc_driver_class" => "org.postgresql.Driver",
"jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
"staging_directory" => temp_import_path_plugin,
"jdbc_connection_string" => jdbc_connection_string,
"loaders" => [
{
"id" =>"servers",
"query" => loader_statement,
"local_table" => "servers"
}
],
"local_db_objects" => local_db_objects,
"local_lookups" => [
{
"query" => lookup_statement,
"prepared_parameters" => ["[host][ip]", "[host][name]"],
"target" => "server"
}
]
}
end

it "enhances an event" do
plugin.register
plugin.filter(event)
expect(event.get("server")).to eq([{"ip"=>"10.3.1.1", "name"=>"mv-server-1", "location"=>"MV-9-6-4"}])
end
end

context "under normal conditions with query with multiple named parameters" do

let(:event) { LogStash::Event.new("host" => { "ip" => "10.3.1.1", "name" => "mv-server-1"}, "message" => "ping") }
let(:lookup_statement) { "SELECT * FROM servers WHERE ip = :host_ip AND name = :host_name" }

let(:settings) do
{
"jdbc_user" => ENV['USER'],
"jdbc_password" => ENV["POSTGRES_PASSWORD"],
"jdbc_driver_class" => "org.postgresql.Driver",
"jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
"staging_directory" => temp_import_path_plugin,
"jdbc_connection_string" => jdbc_connection_string,
"loaders" => [
{
"id" =>"servers",
"query" => loader_statement,
"local_table" => "servers"
}
],
"local_db_objects" => local_db_objects,
"local_lookups" => [
{
"query" => lookup_statement,
"parameters" => {
"host_ip" => "[host][ip]",
"host_name" =>"[host][name]"
},
"target" => "server"
}
]
}
end

it "enhances an event" do
plugin.register
plugin.filter(event)
expect(event.get("server")).to eq([{"ip"=>"10.3.1.1", "name"=>"mv-server-1", "location"=>"MV-9-6-4"}])
end
end

context "under normal conditions when index_columns is not specified" do
let(:local_db_objects) do
[
Expand Down