Setting the value of variable in ruby logstash

I am trying to set the value in ruby logstash variable but it is saying me undefined variable.

if "el5" in [message] {
ruby {
init => "@@linuxversion='5'"
code => "event.set('linux','(@@linuxversion)')
puts linux"
}
drop {}
}

I am getting error :

06:21:54.143 [[main]>worker0] ERROR logstash.filters.ruby - Ruby exception occurred: undefined local variable or method `linux' for #LogStash::Filters::Ruby:0x5d1d0122

I want to use this variable through out in my logstash filter.

Can you help how to resolve this issue ?

Just remove the line I've pointed.

if "el5" in [message] {
    ruby {
    init => "@@linuxversion='5'"
    code => "
        event.set('linux',@@linuxversion)
        puts linux <--- this line is the issue
    "
    }
    drop {}
}

Also, why are you using a drop just after the ruby filter? It will discard the event althogether.

I need to set the variable value on the basis of this line and then use in further cases. Nd also i dont want to parse this line as this is of none use except that.

If you set a field value with event.set('fieldname') you can retrieve it with event.get('fieldname').

I need to set the variable value on the basis of this line and then use in further cases.

You mean future events? Then you can't use event.set(). That sets a field in the current event which isn't carried over to other events. Setting a variable like @@linuxversion might work though.

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