JDBC Input Plugin: extracting the statement as a field in Logstash?

We have our JDBC input working well, and we're trying to see if we can log our SQL statement with the query result.

Here is our config:

input {
  jdbc {
    jdbc_driver_library => "/usr/share/java/mysql.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://localhost:3306/db_name"
    jdbc_user => "username"
    jdbc_password => "password"                                                                                             
    schedule => "* * * * *"
    statement => "SELECT NOW()"
  }
}

We tried adding:

    add_field => {
      "statement" => "%{statement}"
    }

But this doesn't seem to work :confused:

I think the only possible way to achieve this is to copy the statement as is to the new field. You cannot refer to the config values with %{} notation, because that is for the fields in the event itself, not in the config.
So my suggestion is to duplicate the statement in the add_field part.

1 Like

That would work too :slight_smile:

Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.