No implicit conversion of Fixnum into String when adding days to a date

Hi,

I am trying to add day(s) to a date in logstash, based on a filebeat prospector configuration, but when I try adding, I get an error like this:

[2019-03-31T16:43:14,624][ERROR][logstash.filters.ruby    ] Ruby exception occurred: no implicit conversion of Fixnum into String

Here is the code:

mutate { add_field => { "[@metadata][record_date]" => "%{@timestamp}" } }
date {
	match => [ "[@metadata][record_date]", "YYYY-MM-dd HH:mm:ss,SSS" ]
	target => "[@metadata][record_date]"
}

mutate { add_tag => ["debug_tag_before_inside_if_pruning_frequency_12"] }
	mutate { add_field => { "[@metadata][date_format]" => "%Y.%m.%d" } }

# Set expiration date based on the provided retention value (if not provided, assume the default value)
ruby {
	code => "
		event.set('[@metadata][expiry_index]', (event.get('[@metadata][record_date]') + (86400 * (event.get('retention')))).strftime(event.get('[@metadata][date_format]')));
	"
}

I broke down the ruby code, and the error happens when trying to add the 86400 * the number of days to the date. Here are the values for the fields:

"@metadata" => {
    "record_date" => "2019-03-31T20:43:07.227Z",
    "date_format" => "%Y.%m.%d",
},
"retention" => 15

Any help will be very appreciated.

Thanks,
Rob

You should also see this in your metadata.

 "@metadata" => {
    "record_date" => "2019-03-31T22:26:50.650Z",

That does not match the pattern you are using in your date filter. Change that to

match => [ "[@metadata][record_date]", "ISO8601" ]

you will then no longer get the _dateparsefailure, and out pops

 "@metadata" => {
     "record_date" => 2019-03-31T22:27:50.654Z,
    "expiry_index" => "2019.04.15",
     "date_format" => "%Y.%m.%d"
},
1 Like

@Badger, you made it. Thanks a lot!

Regards,
Rob

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