I'm using logstash to manage my catalina logs.
The issue I encounter is the fact that I have to type of timestamp in my logs.
2017-04-04 10:16:54,297
04-Apr-2017 10:16:54.443
Here my filter configuration
filter {
if [type] == "catalina"{
if [message] !~ /(.+)/ {
drop { }
}
grok {
match => [
"message", "%{TOMCAT_DATESTAMP2:timestamp} %{GREEDYDATA:ActiveThread} %{LOGLEVEL:loglevel} %{USERNAME:auth}? %{USERNAME:ident}? %{USERNAME:ident}? %{IP:clientip}? %{NOTSPACE:request}? [%{GREEDYDATA:service}] %{GREEDYDATA:message}",
"message", "%{DATESTAMP2:timestamp} %{LOGLEVEL:loglevel} [%{NOTSPACE:service}] %{GREEDYDATA:message}"
]
}
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss,SSS" ]
target => "@timestamp"
}
}
}
For my fisrt type of timestamp, I don't have any issue but for the second one I always get the tag _dateparsefailure.
Then I'm trying to find a way to convert 04-Apr-2017 to 2017-04-04 to avoid this failure.
Cleverly, you can put two or more potential matches in your date filter by comma separating them:
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss,SSS", "dd-MMM-yyyy HH:mm:ss,SSS" ]
# target => "@timestamp" # You don't need this, it's the default behavior
remove_field => [ "timestamp" ]
# This will automatically remove the now redundant `timestamp` field if the date filter
# successfully converts. It will leave the field alone if it can't convert.
}
The first match wins, so I would put whichever format occurs more frequently first to reduce second checks.
I've tried it and I still have the date parse failure
"type" => "catalina",
"timestamp" => "04-Apr-2017 10:16:54.497",
"tags" => [
[0] "_dateparsefailure"
My bad! It's a cut and paste error on my part. The second timestamp has a decimal, not a comma, separating the milliseconds. Try this:
date {
match => [ "timestamp" , "yyyy-MM-dd HH:mm:ss,SSS", "dd-MMM-yyyy HH:mm:ss.SSS" ]
# target => "@timestamp" # You don't need this, it's the default behavior
remove_field => [ "timestamp" ]
# This will automatically remove the now redundant `timestamp` field if the date filter
# successfully converts. It will leave the field alone if it can't convert.
}
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.