message_array = event.get("message").split("\n\n[")
message_array.each do | index |
if index!=0
event.set("Rule#{index}", "[" + message_array[index])
end
end
I am getting the error on run:
[2018-02-08T19:01:18,716][ERROR][logstash.filters.ruby ] Ruby exception occurred: can't convert String into Integer
The problem is in the line: event.set("Rule#{index}", "[" + message_array[index])
In order to be able to iterate over an array's index you'll need each_index, not each.
So you generally have: each |item| : iterates over items. each_index |index| : iterates over indices. each_with_index |item, index| : iterates over both.
As for the string to int error, it's probably due to some interpolation issue. Always try and explicitly convert types to avoid such pitfalls.
So the above would be:
message_array = event.get("message").split("\n\n[")
message_array.each_index do | index |
if index!=0
event.set("Rule"+index.to_s, "[" + message_array[index].to_s)
end
end
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.