I am new to Logstash and have a requirement to add 1 day to the date(Businessdate) and compare log event date with Businessdate. Can you please suggest how to achieve this.
Ex: Parsed string to extract YEAR, MONTH AND day
grok {
match => ["BusinessDate", "%{YEAR:year}%{MONTHNUM:month}%{MONTHDAY:day}"]
} #Setting time to 3am
mutate {
add_field => {
ExpectedTime => "03:00:00:000"
}
}
#Making date time
mutate {
add_field => {
BusinesDateTime => "%{year}-%{month}-%{day} %{ExpectedTime}"
}
}
#Convert/match to Datetime
date
{
match => ["BusinesDateTime", "YYYY-MM-DD HH:mm:ss.SSS"]
}
Now i would like to add 1 day to the "BusinessDateTime".
When i read some of existing posts, it says use "ruby" plug-in. Please let me know how to use ruby functions to add 1 day.
Thank you Jenni for the info. I have tried but getting below error. Can you please advise anything is missing in the code
Error
[2018-04-24T09:43:48,356][ERROR][logstash.filters.ruby ] Ruby exception occurred: no implicit conversion of Fixnum into String
[2018-04-24T09:43:48,356][ERROR][logstash.filters.ruby ] Ruby exception occurred: no implicit conversion of Fixnum into String
[2018-04-24T09:43:48,357][ERROR][logstash.filters.ruby ] Ruby exception occurred: no implicit conversion of Fixnum into String
The default target of date{} is @timestamp. So your BusinesDateTime is not a LogStash::Timestamp at this point, but a string. If you want to convert BusinesDateTime to a timestamp, you have to specify this field as the target. That's probably causing the error.
There's probably something wrong with the BusinesDateTime value before the ruby filter, so the UNIX timestamp that the new Timestamp object is based on, is 0+86400 = 1970-01-01 plus one day.
... Your ExpectedTime ends with ':000', but your pattern ends with '.SSS'.
Thank you for spotting the issue Jenni. Your solution is working . Thank you.
BusinesDateTime BusinesDateTimeConverted LogEventTimeStamp
2018-01-19T08:00:00.000Z 2018-01-20T08:00:00.000Z April 19th 2018, 13:15:09.000
From the above the BusinessDateTime is : 2018-01-19 03:00:00.000
Can you please advise what to do to get to YYYY-MM-DD HH:MI:SS.SSS format. The reason is i need to compare both logEventTimeStampand BusinessDateTimeConverted
I would like to see both "BusinessDateTimeConverted" and "LogEventTImeStamp" to "YYYY-MM-DD HH:MI;SS.SSS" format.Currently it is showing as "2018-01-19T08:00:00.000Z" format.
Business Datetime Converted doesn't really have a fixed format as it is not a string, but a Timestamp object. 2018-01-19T08:00:00.000Z is Logstash's way of displaying it. You could build a formatted string from that Timestamp again. But wouldn't Timestamp objects be more useful for comparisons?
[2018-04-25T09:46:11,762][ERROR][logstash.agent ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_i
or", :message=>"Expected one of #, => at line 114, column 8 (byte 2728) after filter {\n\t\t\n\t#Match patterns based on source log origin
Could you post more of your configuration? The text snippet in those syntax error logs usually ends right before the error. So I'm not sure if the wrong part is even included in the code you posted.
"LogEventTimeStamp" and "BusinesDateTimeConverted" are strings. You want to compare the field values [LogEventTimeStamp] and [BusinesDateTimeConverted] (if these are both timestamps)
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.