I'm using logstash 7.5.1. I would like to parse through all fields of my logstash and convert field starting with the word "time" to float. Please find below my configuration:
filter {
# Parse Search Logs
grok {
match => [ "message", "%{USERNAME:trans_id} %{USERNAME:trans_name} %{USERNAME:sub_trans_name} %{BASE16FLOAT:time_elapsed} %{USERNAME:trans_status} %{GREEDYDATA:payload}" ]
}
# Extract the time based on the time of the query and
# not the time the item got logged
#date {
# match => [ "timestamp", "yyyy-MM-dd HH:mm:ss.SSSSSS" ]
#}
# Drop the captured timestamp field since it has been moved to the
# time of the event and drop user1 which are unwanted fields
#mutate {
# remove_field => [ "timestamp" ]
#}
mutate {
add_field => { "%{sub_trans_name}_trans_status" => "%{trans_status}" }
add_field => { "%{sub_trans_name}_payload" => "%{payload}" }
add_field => { "time_elapsed_%{sub_trans_name}" => "%{time_elapsed}" }
remove_field => [ "sub_trans_name", "trans_status", "payload" ]
}
ruby {
code => "
event.to_hash.keys.each { |k|
if k.start_with?('time') and event[k].is_a?(String)
event[k] = event[k].to_float
end
}
"
}
}
I get Ruby exception occurred: undefined method `' for #<LogStash::Event:0x1f8ee438 when i try to parse logs:
Sample Log: 980f884e7a2f11 search pre-process 0.622 1 {question: hello}
Any help would be great, as I have been stuck with this for the entire day.