Hi, I have a bunch of PHP log to add to my ELK cluster and i cannot get the @timestamp to work. I'm pretty sure it has something to do with the config file and the date format used in the PHP logs.
Here's my config file's Filter block ::
filter {
# ignore log comments
if [message] =~ "^#" {
drop {}
}
grok {
match => ["message", "\[(?<datetime>(%{MONTHDAY:day}-%{MONTH:month}-%{YEAR:year} %{TIME})) (?<timezone>([\a-zA-z\s\\]*))\] (?<message>(.|\r|\n)*)"]
}
date {
match => ["datetime", "DD-MMM-yyyy HH:mm:ss"]
target => "@timestamp"
}
}
And here's a line of log ::
[03-Jun-2022 15:31:44 America/New_York] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function KhamaiController::getTelevisionPackages(), 4 passed in /home/papi/public_html/library/shared.php on line 48 and exactly 5 expected in /home/papi/public_html/application/controllers/khamai.php:527
Stack trace:
#0 /home/papi/public_html/library/shared.php(48): KhamaiController->getTelevisionPackages('96,84,103,83,86...', '1924,7054,7210,...', 'FR', '')
#1 /home/papi/public_html/library/shared.php(76): callHook()
#2 /home/papi/public_html/library/bootstrap.php(3): require_once('/home/papi/publ...')
#3 /home/papi/public_html/index.php(22): require_once('/home/papi/publ...')
#4 {main}
thrown in /home/papi/public_html/application/controllers/khamai.php on line 527
When i use the grok debugger i can successfully tag the datetime as one variables but it doesnt replace @timestamp.
if you change DD (day of the year, so this forces the month to January) to dd then it does work (19 rather than 20 because January does not have DST but June does)
"@timestamp" => 2022-06-03T19:31:44Z,
Note also that since your grok has a field called 'message' the [message] field will end up as an array containing the original message and your new message string. You may want to look at the overwrite option of the filter.
So yeah i can change the value to "dd" But even then, in your example, it was putting the @timestamp for today instead of the real one which should be 2018 (in my example)
About the [message], i understand your point, i should name my last variable something else.. or not put "message" , in front of the Grok match ?!
As you can see, i was able to name my variable "datetime" and the Grok parser gets it too. But even if i do the match in my filter, it does not replace @timestamp.
As far as my example goes :
The @timestamp took is not reflecting the right datetime (it's not the same set of dates as my screenshot but it's all the same in the end)
In the second example the date filter failed for some reason that is still unclear.
I've replaced the date in the sample message that you shared to 05-Dec-2018 18:24:16 and the following date filter worked without any problem:
date {
match => ["datetime", "dd-MMM-yyyy HH:mm:ss"]
target => "@timestamp"
}
Can you share the full line from the event where you have _dateparsefailure? Also, can you share other examples where the date filter failed to see if there is any pattern on them?
[05-Dec-2018 18:24:16 America/New_York] PHP Notice: Undefined variable: langue in /home/papi/public_html/application/controllers/khamai.php on line 197
Another example :
[05-Dec-2018 19:12:29 America/Toronto] PHP Notice: Trying to get property of non-object in /home/papi/public_html/application/models/ipblock.php on line 28
And another:
[14-Aug-2018 06:31:20 America/New_York] PHP Notice: Undefined variable: langue in /home/papi/public_html/application/controllers/khamai.php on line 210
I tried different things, with a smaller data set.. Trying to see where it could fail. So i created a new field "newdatetime" then i tried to associate the datetime to it :
grok {
match => {"message" => "\[(?<datetime>(%{MONTHDAY:day}-%{MONTH:month}-%{YEAR:year} %{TIME:time})) %{DATA:timezone}\] (?<message>(.|\r|\n)*)"}
overwrite => ["message"]
}
mutate{
add_field => {"newdatetime"=>""}
}
date {
match => ["datetime","dd-MMM-yyyy HH:mm:ss"]
target => "newdatetime"
}
Here's the result... :
{
"type" => "phpApi",
"datetime" => "08-Jul-2018 00:38:24",
"@timestamp" => 2022-06-06T20:30:35.431Z,
"day" => "08",
"timezone" => "America/Toronto",
"message" => "PHP Notice: Trying to get property of non-object in /home/papi/public_html/application/models/ipblock.php on line 28",
"host" => "webhost01.int.cablevision.ca",
"tags" => [
[0] "_dateparsefailure"
],
"year" => "2018",
"@version" => "1",
"month" => "Jul",
"path" => "/home/papi/logs/php_error_test_log",
"time" => "00:38:24",
"newdatetime" => ""
}
[DEBUG] 2022-06-07 08:24:44.552 [Converge PipelineAction::Create] DateFilter - Date filter with format=dd-MMM-yyyy HH:mm:ss, locale=null, timezone=null built as org.logstash.filters.parser.JodaParser
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.