Hi ,
I need to poll http endpoint from logstash using http_poller plugin and parse the json response to fetch the values and derive custom fields based on that.
Below is my response sample json output that need to parsed and derive some fields based on that.
{ "response" : {
"root": {
"mode": "master",
"node-id": "master.host.com"
"connected-slave": ["slave.host1.corp.com","slave.host2.corp.com"]
}
}
}
Below is my logstash (version 6.6.0) code in ruby:
if ([response]) {
ruby {
code => "
require 'json'
jsondata = event.get('response')
parsed = JSON.parse(jsondata)
parsed['root'].each { |hash|
if #{hash['mode']} == 'master'
event.set('df_mode', 'master')
end
}
"
}
}
While running this configuration, I am running into "Hash cannot convert to String ruby exception". And I tried other ways also but not helped though. Please provide some light or with sample code, how i could get the values of each key which i need to set as custom fields values.
Thanks
Sukumar C