logstash - use ruby code inside of a filter

非 Y 不嫁゛ 提交于 2020-01-05 08:31:58

问题


is it possible to use ruby code inside of a filter? something like this:

filter {
 csv{
   ruby {
      code => "
            fieldArray = event['message'].split(',')
            for field in fieldArray
                event[field] = field
            end
        "
        }
   }
}

回答1:


No, csv{} is a filter and ruby{} is a filter, so they don't nest inside each other as you've shown.

You haven't described the problem, but perhaps just using ruby{} is what you're looking for.

EDIT: with more information on the problem, here are some more notes:

Logstash runs one event at a time, so for csv{}, it's processing one line from the file at a time. Even with the ruby{} filter, you don't get a look at the entire input.

Since the header row is first, however, you should be able to drop into ruby{}, tuck away the columns of this row into a persistent variable, and, for subsequent rows, loop through the fields in ruby and rename them.

You could also extend the csv{} filter to be "header aware", which would benefit a good population of logstash users.



来源:https://stackoverflow.com/questions/32093690/logstash-use-ruby-code-inside-of-a-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!