Ruby script initialize variable only once

Sorry, not sure if my problem falls under Logstash or plain Ruby.

Using ruby script, how do I initialize my variable only once? I get that the script would be executed for every events, is it possible to have something like initialize function to only execute once?

Using init, I able to initialize it and use at code configuration. But was unable to retrieve the variable at ruby script.

Here is my current code

init => "$links = Net::HTTP.get(URI('http://localhost:8085/link/all'))"
path => "./filter.rb"

From the ruby script, I couldn't access the $links variable

Thanks in advance.

Update

Found out register(params) is the initializer

def register(params)
end

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