Logstash 2.3.4
I have dates extracted from the log lines using the date filter. I want to drop any log line which is older than 5 days and not put it into Elasticsearch at all.
Is there a standard filter which does this or at least identifies older log lines already or do I need to use a ruby filter? Due to complications with corporate process (please don't ask) it would be hard for me to install a community plugin which isn't included with the normal Logstash installation.
This issue has come up as sometimes we start Logstash on a VM which hasn't been run in a while and ancient log files get picked up which we don't want.
Yeah, I believe you'd have to use a ruby filter. The @timestamp field is of a timestamp type so doing date arithmetic to determine how old it is should be easy.
Thank you so much. I'll try running through this, does this only grab files that are less than 5 days old? If so is there something that I can add that will also filter out the lines in a file for the same thing (X days) ?
In the Ruby code the 432000 is the number of seconds old that a log line is allowed to be. In this example if it is older than 5 days old it will be dropped (event.cancel).
As the Ruby plugin is a filter it only applies to files which have already been picked up and are being processed. This isn't anything to do with log file age, but the age of the actual log lines which are set using the date filter.
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.