I have a filter that is reading 2 fields (STARTTIME and ENDTIME) from a CSV file and then changing to deviceCustomString1 and deviceCustomString2 and I need to change the time layout. I am trying to change the time format from say 7/6/2021 8:29:58 AM to epoch (MMM dd yyyy HH:mm:ss) can this be done?
If you want those fields to be strings in a particular format then I suggest using a date filter to parse them into LogStash::Timestamp objects, then ruby and strftime to set the format you want. Something like this
date {
match => [ "deviceCustomDate1", "M/d/YYYY h:mm:ss a" ]
target => "[@metadata][deviceCustomDate1]"
}
ruby {
code => '
t = Time.at(event.get("[@metadata][deviceCustomDate1]").to_f)
event.set("deviceCustomDate1", t.strftime("%b %d %Y %H:%M:%S"))
'
}
Not sure if you want to replace %d with %-d or %e.
Thanks this worked. The only issue I am having is sometimes there is no data in the deviceCustomDate1 and deviceCustomdate2 fields and when I add the above syntax it adds the below to the empty field. Is there a way to keep this empty when there is no data an not input Dec 31, 1969?
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.