Build an Elastic stack where I have to connect to a MSSQL Database. So I build my own Logstash image where I import the JDBC driver to the container.
FROM docker.elastic.co/logstash/logstash:6.3.0
USER root
COPY mssql-jdbc-6.4.0.jre9.jar /opt/
# Add your logstash plugins setup here
RUN logstash-plugin install logstash-input-jdbc
# Example: RUN logstash-plugin install logstash-filter-json
Then I launch my docker-compose file.
# Elastic and Kibana config remove for clarity
logstash:
# image: docker.elastic.co/logstash/logstash:${TAG}
build: logstash/
container_name: Logstash
environment:
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
env_file:
- .env
ports:
- '5001:5001'
volumes:
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml
- ./logstash/pipeline:/usr/share/logstash/pipeline
depends_on:
- elasticsearch1
networks:
- esnet
Here my logstash.conf
input {
jdbc {
jdbc_driver_library => "/opt/mssql-jdbc-6.4.0.jre9.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://****.database.windows.net"
jdbc_user => "${DB_USERNAME}"
jdbc_password => "${DB_PASSWORD}"
statement => "select * from *****.dbo.association"
}
}
output {
elasticsearch {
hosts => ["http://elasticsearch1:9200", "http://elasticsearch2:9200"]
}
stdout {
codec => rubydebug
}
}
Then I got this error. Error: com.microsoft.sqlserver.jdbc.SQLServerDriver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?