I implemented the same using ruby filter plugin.
My logstash config is something like this :-
input
{
file
{
path => "/usr/share/logstash/bin/csvt1/*.csv"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter
{
if "Book0" in [path] {
mutate {
replace => {
"type" => "Book0"
}
}
}
if "Book1" in [path] {
mutate {
replace => {
"type" => "Book1"
}
}
}
if "Book2" in [path] {
mutate {
replace => {
"type" => "Book2"
}
}
}
if [type] == "Book0"
{
csv
{
autodetect_column_names => true
separator => ","
convert => {
"timestamp" => "date_time"
"price" => "float"
"quantity" => "integer"
"brokerid" => "integer"
"clientid" => "integer"
"orderid" => "integer"
"tradeid" => "integer"
}
}
date{
match => ["timestamp" , "dd-MM-yyyy HH:mm:ss"]
timezone => "Asia/Kolkata"
}
}
if [type] == "Book1"
{
csv
{
autodetect_column_names => true
separator => ","
convert => {
"timestamp" => "date_time"
"price" => "float"
"quantity" => "integer"
"brokerid" => "integer"
"clientid" => "integer"
"orderid" => "integer"
}
}
date{
match => ["timestamp" , "dd-MM-yyyy HH:mm:ss"]
timezone => "Asia/Kolkata"
}
}
if [type] == "Book2"
{
csv
{
autodetect_column_names => true
separator => ","
convert => {
"timestamp" => "date_time"
"price" => "float"
"quantity" => "integer"
"brokerid" => "integer"
"clientid" => "integer"
"tradeid" => "integer"
}
}
date{
match => ["timestamp" , "dd-MM-yyyy HH:mm:ss"]
timezone => "Asia/Kolkata"
}
}
ruby
{
init => "
@@map_to = {};
@@map_ot = {};
"
code => '
if event.get("tradeid") and event.get("orderid")
@@map_to[event.get("tradeid")] = event.get("orderid");
@@map_ot[event.get("orderid")] = event.get("tradeid");
elsif event.get("tradeid")
event.set("orderid" , @@map_to.fetch(event.get("tradeid") , nil));
elsif event.get("orderid")
event.set("tradeid" , @@map_ot.fetch(event.get("orderid"), nil));
end
'
}
}
output
{
stdout
{
codec => rubydebug
}
}
But now i am getting nil for most the values. I thought the problem is occurring due to the multiple pipeline workers, so i tried running logstash with following command
./logstash -f file.conf -w 1
But even then also I am getting nil values.
Thanks in advance!