How to move ruby code from logstash.conf into ingest pipeline?


(Agnes) #1

I've a logstash configuration file which contains ruby code.
How can I script the ruby part of the logstash filter in ingest pipeline?

It's a server with filebeat.
All part except the ruby code I "moved" into the ingest pipline definition.

my_logstash.conf

filter {
csv {
columns => ['BL','MA',OffsetByte,'LengthByte']
separator => ";"
autogenerate_column_names => false
}
mutate {
add_field => { "my_stats" => "%{path}" }
convert => {
"LengthByte" => "integer"
}
}
ruby {
code => "
stats = IO.read(event.get('my_stats'), event.get('LengthByte'), event.get('OffsetByte') )
linecount = stats.scan(/\n/).count
event.set('Statistics', stats[0..-(linecount+1)])
"
}

}
}


(Christian Dahlqvist) #2

Ingest node pipelines do not support Ruby, so the only way I can think of would be to try and move this logic into a painless script.


(Agnes) #3

I'll give a try

"filters": [
{
"ruby": {
"code": "stats = IO.read(event.get('path_stats'), event.get('LengthByte'),event.get('OffsetByte')) linecount = stats.scan(/\n/).count event.set('Statistics', stats[0..-(linecount+1)])"
}
}
],

later more, when tested


(Agnes) #4

IO.read -> cannot access Input file via Pipeline, so this is not a solution