Closed cawoodm closed 6 years ago
There are 2 ways you can do this already;
Sorry I just re-read your question.
The connection is established and a pool of connections is maintained before any events come through. A connection is not made per-event, so it's impossible to use any fields in an event to alter the connection string.
So, if we use the if
statement approach with 2 jdbc output plugins it should still work? Would be a pity if the connection pools co-mingled...
if [@metadata][system] == "prod" {
jdbc {
driver_jar_path => 'D:\prg\cmd\mssql-jdbc-6.4.0.jre8.jar'
connection_string => "jdbc:sqlserver://prodserver:1433;databaseName=foo;user=reporting;password=****"
statement => [ "EXEC LogImport ?, ?", "timestamp", "message"]
}
} else {
jdbc {
driver_jar_path => 'D:\prg\cmd\mssql-jdbc-6.4.0.jre8.jar'
connection_string => "jdbc:sqlserver://devserver:1433;databaseName=foo;user=reporting;password=****"
statement => [ "EXEC LogImport ?, ?", "timestamp", "message"]
}
}
The pools wont co-mingle in that example.
Each jdbc{} statement gets treated by logstash as a separate entity and you'll get separate connection pools :)
Is there any way to parameterize the connection string with
%{[myfield]}
?Say we have a metadata field called
dbserver
we'd like to do this:Without this you need
if {}
statements to separate data into different databases (e.g. for PROD and TEST environments).