logstash-plugins / logstash-input-jdbc

Logstash Plugin for JDBC Inputs
Apache License 2.0
449 stars 187 forks source link

MSSQL - database name taken from parameter adds N'' making query invalid #333

Open PiotrBB opened 5 years ago

PiotrBB commented 5 years ago

Hello,

Here's my logstash config file:

input {
jdbc {
parameters => {
database => ABC
}
jdbc_driver_library => "/usr/share/logstash/lib/drivers/sqljdbc42.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "server:1433"
jdbc_user => "login"
jdbc_password => "pwd"
schedule => "*/1 * * * *"
statement_filepath => "/etc/logstash/conf.d/query.sql"
use_column_value => true
tracking_column_type => "numeric"
tracking_column => "id"
last_run_metadata_path => "/usr/share/logstash/last_run_metadata/.query"
record_last_run => true
}
}

The query looks like this: select * from :database.dbo.table

Logstash is unable to retrieve any result, due to an error with the query. In the log i can see that's it's trying to execute the following:

select * from N'ABC'.dbo.table

Is there a way to get rid of N'' when parameter is used for database name?

guyboertje commented 5 years ago

Sequel is trying to provide an appropriate datatype for the substitution because it expects that substitutions are done in WHERE clauses, i.e. dynamic values.

A solution for your dynamic needs might be to use ENV variables in the statement_filepath => "/etc/logstash/conf.d/query.sql" setting.

statement_filepath => "/etc/logstash/conf.d/$DB-query.sql" and $DB -> "ABC"