Nested json parsing - data from api

Hi Team,

Below is my input file.

{
"sessionHost": "127.0.0.1",
"sysrep_physicaldiskspacedata": {
"links": [{
"href": "https://127.0.0.1:8080/api/v1/systemreporter/attime/physicaldiskspacedata/hourly",
"rel": "self"
}]
}
}

Logstash config is:
input {
file {
path => ['/home/sample.json']
start_position => "beginning"
tags => ['sample']
type => "sample"
codec => "json"
}
}

filter{
if [type] == "sample" {
json {
source => "message"
}
ruby {
code => '
arrayOfEvents = Array.new()
ts = event.get("sysrep_physicaldiskspacedata")
ts.each do |data|

            arrayOfEvents.push(data)
        end
        event.set("event",arrayOfEvents)
    '
    remove_field => ["sysrep_physicaldiskspacedata" ]
}
split {
    field => 'event'
}

    }

}

output {
stdout {
codec => "rubydebug"
}
}

Error:
[ERROR] 2019-03-12 06:41:44.276 [Ruby-0-Thread-7: :1] ruby - Ruby exception occurred: undefined method each' for nil:NilClass [ERROR] 2019-03-12 06:41:44.316 [Ruby-0-Thread-6: :1] ruby - Ruby exception occurred: undefined methodeach' for nil:NilClass
[ERROR] 2019-03-12 06:41:44.323 [Ruby-0-Thread-4: :1] ruby - Ruby exception occurred: undefined method `each' for nil:NilClass
[WARN ] 2019-03-12 06:41:44.354 [Ruby-0-Thread-4: :1] split - Only String and Array types are splittable. field:event is of type = NilClass

How to fix this?

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