hi everyone !
in order to factoring my logstash configuration i wanna replace many similar ruby inline code by a ruby script with dynamic param.
what i got before my ruby code :
[
'key1 => 'value1',
'key2 => 'value2'
]
what i need after :
?key1=value1&key2=value2
this inline ruby work fine :
# construct the cleaned params string for canonical params
# there isn't functions in logstash to implode array so we used "Ruby" code
if [og_url_param_decode_array] {
ruby {
code => "
param_string='?'
event.get('[og_url_param_decode_array]').each { |k, v|
param_string+=k+'='+v+'&'
}
event.set('og_url_param_decode', param_string.chomp('&'))
"
}
}
but when i'm try to do the same thing in a ruby script i can't get input data from the event if it's an array but this work normaly if i try to get a string
see the script bellow
def register(params)
@input_var_name = params["var_name"]
end
def filter(event)
param_string='?'
event.get(@input_var_name).each { |k, v|
param_string+=k+'='+v+'&'
}
event.set('test', param_string)
return [event]
end
this is how the script is called
ruby {
path => "/etc/logstash/ruby/create_url_param.rb"
script_params => { "var_name" => canonical_param_decode_array }
}
if canonical_param_decode_array is an array my logstash pipeline is not working