Hello,
I read the documentation about the ruby script and I did not correctly understand the conversion of the ruby script into a file.
If I have a converted ruby script into a file, do I have to rewrite the script into classes?
For example, I wanted to put this ruby script in a file, but it didn't work there at all. When I have this in filter section, it works:
ruby {
code => "
event.set('[event][duration_seconds]', event.get('[event][duration]').to_f / 1000)
"}
I put it into the file. In the filter was:
ruby {
path => "{{logstash.scripts_path}}/count.rb"
}
The content of the file was:
event.set('[event][duration_seconds]', event.get('[event][duration]').to_f / 1000)
Why it didn´t work?
Thank you
Regards,
Catherine
Badger
July 11, 2023, 4:25pm
2
To convert an inline script to a file you need to define two functions. Try creating a file containing
def register (params)
end
def filter (event)
event.set("[event][duration_seconds]", event.get("[event][duration]").to_f / 1000)
return [event]
end
I understand. Thank you so much!
Is possible to add also ruby id? I mean: id => "X1_RUBY"
ruby {
id => "X1_RUBY"
code => "
event.set('[event][duration_seconds]', event.get('[event][duration]').to_f / 1000)
"}
Badger
July 12, 2023, 2:45pm
4
Yes, id is a common option that all filters support.
Thank you so much. It works all perfectly.
Regards,
Catherine
system
(system)
Closed
August 14, 2023, 9:27am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.