If conditions in Ruby code in Logstash


(Ömer Uludağ) #1

Hello together,

I am new in the Elasticsearch Ecosystem. For that reason, I have unfortunately some problems with the syntax of Ruby in Logstash.
I have the following snippet code:
if [Clat] != '' { ruby { code => " if !event['Clat'].to_s.include? "." event['Clat'].to_f event['Clat'] = event['Clat'] * 360 / (4294967296) event['Clat'] = event['Clat'].round(2) else event['Clat'].to_f event['Clat'] = event['Clat'].round(2) end " } }
Other parts of the code are working. The error message is:
Error: Expected one of #, {, } at line 42, column 50 (byte 1145) after filter{
It points on my first line:
if !event['Clat'].to_s.include? "."

Probably, logstash has problems with the ruby syntax.

Do you maybe know where the problem can lie? I googled for the ruby syntax and created with that the corresponding ruby code.

Best regards


(Magnus Bäck) #2

The code block itself is double quoted so you can't have double quotes inside it unless you escape the quotes. I suggest you go with single quotes in all places of your code.


(Ömer Uludağ) #3

thank you very much :slight_smile: nice suggestion :slight_smile:


(system) #4