Search code examples
sql-serverelasticsearchlogstashelastic-stacklogstash-jdbc

undefined method `close_jdbc_connection' for #<Sequel::JDBC::Database:0 x764acb8b>


I have been trying to import data from MS SQL Server to Elastic Search using Logstash. However, I am getting logstash pipeline and undefined method `close_jdbc_connection' error. I have not found the exact solution for this issue. The code used and error messages are as follows -

logstash config -

input {
  jdbc {
   jdbc_driver_library => "C:\elasticsearch-5.4.3\elasticsearch-5.4.3\lib\sqljdbc42.jar"
   jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
   jdbc_connection_string => "jdbc:sqlserver://<servername>,<portname>;databaseName=<db_name>"
   jdbc_user => "user"
   jdbc_password => "password"
   statement => "select * from dbo.jobstatus"
   jdbc_paging_enabled => "true"
   jdbc_page_size => "50000"
   }
}
filter {
    mutate {
        remove_field => [ "message", "path", "score", "@version", "host" ]
    }
    #mutate { convert => ["REGCONNTYPEID","integer"]}
}

output {
    elasticsearch {
        hosts => "localhost"
        index => "sql_elk_dc_stats"
        document_type => "devices"
    }
    stdout { codec => rubydebug { metadata=> true } }
}

Output -

[2017-10-15T18:20:11,768][INFO ][logstash.agent           ] Successfully started
 Logstash API endpoint {:port=>9600}
[2017-10-15T18:20:40,971][WARN ][logstash.inputs.jdbc     ] Failed test_connecti
on.
[2017-10-15T18:20:40,978][ERROR][logstash.pipeline        ] A plugin had an unre
coverable error. Will restart this plugin.
  Plugin: <LogStash::Inputs::Jdbc jdbc_driver_library=>"C:\\elasticsearch-5.4.3\
\elasticsearch-5.4.3\\lib\\sqljdbc42.jar", jdbc_driver_class=>"com.microsoft.sql
server.jdbc.SQLServerDriver", jdbc_connection_string=>"jdbc:sqlserver://<servername>,<port>;databaseName=db_name", jdbc
_user=>"user", jdbc_password=><password>, statement=>"select * from dbo.jo
bstatus", jdbc_paging_enabled=>true, jdbc_page_size=>50000, id=>"36bb27ae9af8f6a
086048a0a0f6a22d4a32b1be6-1", enable_metric=>true, codec=><LogStash::Codecs::Pla
in id=>"plain_8d7b9383-b58f-4dfe-82c8-20066ced2652", enable_metric=>true, charse
t=>"UTF-8">, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdb
c_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connecti
on_retry_attempts_wait_time=>0.5, parameters=>{"sql_last_value"=>false}, last_ru
n_metadata_path=>"C:\\Users\\ghosmrin/.logstash_jdbc_last_run", use_column_value
=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>tru
e, lowercase_column_names=>true>
  Error: undefined method `close_jdbc_connection' for #<Sequel::JDBC::Database:0
x764acb8b>

Note - I am using windows 7, ELK 5.4.3 version. The sql login is able to connect to the SQL server.


Solution

  • It looks like there was a bug https://github.com/logstash-plugins/logstash-input-jdbc/issues/227 - that was reported in July - It looks like it made it into the 4.2.4 version of the JDBC plugin https://github.com/logstash-plugins/logstash-input-jdbc/blob/v4.2.4/CHANGELOG.md - are you using an earlier version of the plugin?

    With that said, I suspect the could still be an issue with your connection, the plugin may just be poorly handling a connection issue... As you've sensibly replaced you db/server details it's impossible to categorically say if there's an issue with the connection string... The one thing I'll say is that you need a colon between the server and port (you have a comma), you might also need a semi-colon at the end of the string, but I don't think it's strictly necessary:

    jdbc_connection_string => "jdbc:sqlserver://<servername>:<portname>;databaseName=<db_name>;"

    https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url