发生 Ruby 异常:nil:NilClass 的未定义方法"split"



我在logstash有一个麻烦。我写了下面的代码:

ruby {
code => 'separated = event.get("[request_url]").split("/")
separated.each_index {|x|
temp = "P" + x.to_s
event.set(temp,  separated[x])}'
}

和我得到以下错误:

[2021-07-26T16:27:37,135][ERROR][logstash.filters.ruby    ][main][23b8bf19dac851a85d8c4d86162422f06362d00bf13b156291eea5b597c7f7ec] Ruby exception occurred: undefined method `split' for nil:NilClass {:class=>"NoMethodError", :backtrace=>["(ruby filter code):2:in `block in filter_method'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-filter-ruby-3.1.7/lib/logstash/filters/ruby.rb:93:in `inline_script'", "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-filter-ruby-3.1.7/lib/logstash/filters/ruby.rb:86:in `filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:159:in `do_filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:178:in `block in multi_filter'", "org/jruby/RubyArray.java:1809:in `each'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:175:in `multi_filter'", "org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:134:in `multi_filter'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:295:in `block in start_workers'"]}

我不知道是什么问题!有人能帮我吗?

我应该在使用它之前测试它。所以我把代码改成了:

ruby {
code => 'urls = event.get("[request_url]")
if urls
separated = urls.split("/")
if separated
separated.each_index {|x|
temp = "P" + x.to_s
event.set(temp,  separated[x])
}
end
end'
}

和错误修复。

相关内容

  • 没有找到相关文章

最新更新