Logstash Filter using Ruby Code
Posted: Thu Jul 11, 2019 10:48 am
Now I am looking for Logstash > Filter > Ruby help
Just to test some basic functionality, I have this in a filter file.
It does not make a file in /tmp ... nor does it add the field named clientip
The field x-forwarded-for exists and has an IP address in it. I wanted to make a list in a file. Just as a temporary test.
The field clientip does not exist but I am attempting to add it. Just as a temporary test.
I wanted to take small steps and prove that I can make a field. I wanted to see ruby do anything. Or something.
I am basically working up to getting the code below in place. Ultimately, I need to get the following work.
Please help with this. Is it syntax? Do I need to do something special to make ruby work?
Do I need to install ipaddr in ruby?
Thanks
Steve B
Just to test some basic functionality, I have this in a filter file.
It does not make a file in /tmp ... nor does it add the field named clientip
Code: Select all
ruby {
code => "
File.open('/tmp/mydebug.log','a') { |f| f.puts event['x-forwarded-for'] }
event['clientip'] = 'testing'
"
}
The field clientip does not exist but I am attempting to add it. Just as a temporary test.
I wanted to take small steps and prove that I can make a field. I wanted to see ruby do anything. Or something.
I am basically working up to getting the code below in place. Ultimately, I need to get the following work.
Code: Select all
ruby {
code => "
require 'ipaddr'
event['clientip'] = IPAddr.new(event['c-ip']).strip.to_i
"
}
Do I need to install ipaddr in ruby?
Thanks
Steve B