Filter Ruby configuration Error


#1

I have data that is coming in via Logstash with ActiveMQ bus that looks like this:
"DataType1" => {
"system:subsystem123" => [
[0] {"field": "test}],
"system:subsystem234" => [
[0] { "field": "test"}],
"system:subsystem837" => [
[0] { "field": "test"}],
etc.

I am trying to extract data from DataType1. I want to move the contents of the array
[[0] { "field": "test"}], one level up to be on the same level as "system:subsystem123"
My output should look like:
{ "DataType1": [
{
"system:_subsystem": system101:subsystem123",
"field: test"
}

I have the following ruby:
ruby {
code =>
"event.get('DataType1').each { |e|
h = {}
h['system_subsystem'] = e.first
h.merge! e[1][0]
event.set([DataType1']) << h
}"
}
I am getting the following error:
Ruby exception occurred: wrong number of arguments calling set (1 for 2)

Any advice?


(Paris Mermigkas) #2

event.set takes 2 arguments, the field which it refers and the value to change that field to.
If you want to append values on each iteration, you could try something like this (untested)

ruby {
    code => "
        event.get('DataType1').each { |e|
            h = {}
            h['system_subsystem'] = e.first
            h.merge! e[1][0]
            event.set('DataType1', event.get('DataType1') + [h])}
   "
}

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.