Hi,
An unexpected error in occuring for the following ruby code in logstash filter.
SyntaxError: (ruby filter code):5: syntax error, unexpected tRCURLY
** }**
Following is the ruby code:
ruby {
code => ' allscores = event["score"]
if allscores.length != '1'
t = allscores.inject(:+)
event["total_score"] = t
'
add_tag => [sum_score]
}
The error is as follows:
SyntaxError: (ruby filter code):5: syntax error, unexpected tRCURLY
}
^
eval at org/jruby/RubyKernel.java:1079
register at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-ruby-2.0.5/lib/logstash/filters/ruby.rb:29
start_workers at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:174
each at org/jruby/RubyArray.java:1613
start_workers at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:174
run at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/pipeline.rb:126
execute at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/agent.rb:210
run at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/runner.rb:90
call at org/jruby/RubyProc.java:281
run at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.2.4-java/lib/logstash/runner.rb:95
call at org/jruby/RubyProc.java:281
initialize at /opt/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/task.rb:24
This error does not occur if I use the following code:
ruby {
code => ' allscores = event["score"]
t = allscores.inject(:+)
event["total_score"] = t
'
add_tag => [sum_score]
}
But I get an error
Ruby exception occurred: undefined method `inject' for 5:Fixnum {:level=>:error}
How can these error be mitigated?