Enriching the JSON with the metadata we have in the MySQL database

The enrichment and other processing parts of the data pipeline can be done using filter plugins. We have built a relational database that contains the tables and necessary lookup data for enriching the incoming JSON requests.

Logstash has a jdbc_streaming filter plugin that can be used to do lookups from any relational database and enrich the incoming JSON documents. Let's zoom into the filter plugin section in our Logstash configuration file:

filter {
jdbc_streaming {
jdbc_driver_library => "/path/to/mysql-connector-java-5.1.45-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://localhost:3306/sensor_metadata"
jdbc_user => "root"
jdbc_password => "<password>"
statement => "select st.sensor_type as sensorType, l.customer as customer, l.department as department, l.building_name as buildingName, l.room as room, l.floor as floor, l.location_on_floor as locationOnFloor, l.latitude, l.longitude from sensors s inner join sensor_type st on s.sensor_type_id=st.sensor_type_id inner join location l on s.location_id=l.location_id where s.sensor_id= :sensor_identifier"
parameters => { "sensor_identifier" => "sensor_id"}
target => lookupResult
}

mutate {
rename => {"[lookupResult][0][sensorType]" => "sensorType"}
rename => {"[lookupResult][0][customer]" => "customer"}
rename => {"[lookupResult][0][department]" => "department"}
rename => {"[lookupResult][0][buildingName]" => "buildingName"}
rename => {"[lookupResult][0][room]" => "room"}
rename => {"[lookupResult][0][floor]" => "floor"}
rename => {"[lookupResult][0][locationOnFloor]" => "locationOnFloor"}
add_field => {
"location" => "%{[lookupResult][0][latitude]},%{[lookupResult][0][longitude]}"
}
remove_field => ["lookupResult", "headers", "host"]
}

}

As you will notice, there are two filter plugins used in the file:

  • jdbc_streaming
  • mutate

Let's see what each filter plugin is doing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset