I need to create a new field 'status' if the log field contains a specific string. I tried below code in fluentd but this doesnt work. I need to check if the log field contains the string 'error:' then the new field status should have error else if it has ok it should have ok.
<filter **>
@type record_transformer
enable_ruby true
<record>
status "${\
if record['log'].downcase.include? 'error:'
puts 'error'
elsif record['log'].downcase.include? 'ok:'
puts 'ok'
end}"
</record>
</filter>
Can we use regexp to do this?
I also tried using scan.
<filter **>
@type record_transformer
enable_ruby true
<record>
status ${record["log"].scan(/^.* ([[:<:]]error[[:>:]]|[[:<:]]ok[[:>:]]):.*$/i).first.compact}
</record>
</filter>