How to use ruby script file with parameter?


#1

Hi,

sometimes I used ruby as logstash filter plugin - only the inline functionality until now. Additionally I have to admit, that I am not really fond of ruby.

Now I wanna outsource the code to a script file, but I do not understand the explanation at https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.html

I would like to do the following:

  • create a field which has the current timestamp as value and store it in the event
  • set a part of the name as variable (variable name)

Following ruby code snipped should work:

myTime=timeStart=DateTime.now.strftime("%Q").to_i    
event.set("[logstash][debug][" + name + "]",myTime )    

But I do not understand how to outsource this to a file and how to give the name as parameter.

Can anyone provide an example on this simple issue?

Thanks, Andreas


(Magnus Bäck) #2

From where would name come in your inline Ruby snippet?


#3

its not done yet.

I am looking for a way to set this as parameter / argument when I call the script file inside the logstash filter clause.


(Magnus Bäck) #4

Did you look at the script_params option described in the documentation?


#5

yes, but unfortunately I did not understand it. Maybe too few ruby knowledge...


(system) #6

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.