Hi,
I am trying to parse a simple log file to understand how logstash works.
This is my log format:
2017-06-14 11:17:48 [ad8880] INFO: blah blah blah
And I have built the following grok regex using grok Constructor
%{TIMESTAMP_ISO8601:logsimestamp}%{SPACE}[%{WORD:threadID}]%{SPACE}%{LOGLEVEL:loglevel}:%{SPACE}%{GREEDYDATA:task}
But still I am getting _grokparsefailure as below:
"message":"2017-06-14 11:17:48 [ad8880] INFO: blah blah blah\r","tags":["_grokparsefailure"]}
I tried changing the date format to :
%{YEAR}-%{MONTHNUM}-%{MONTHDAY}%{SPACE}%{TIME}
Build your grok expression gradually and pay attention when things stop working. Start with %{TIMESTAMP_ISO8601:logsimestamp}. Does that work? Then continue with the next (%{TIMESTAMP_ISO8601:logsimestamp}%{SPACE}\[%{WORD:threadID}\]).
May be since the default delimiter is "\n" (as I didnot set any explicitly),\n is getting chopped off before parsing, hence may be only \r is seen. Just my thought, you should be knowing better.I just started using logstash.
Thanks for the reply Magnus!
I have a few thoughts why the result might be different:
I performed this test on Windows 10 with "File input plugin". Are there any chances that there can be any problems with EOL characters or with File opening or closing?
I also performed a small test to analyse the issue.I decided to go step by step upon your advice, So I wanted to see if the setup was correct,
My input file contained:
123
456
789
If the grok pattern is
{
match=>{"message",%{NUMBER}} // This gave me _grokparefailure
}
but the pattern
{
match=>{"message",(?[0-9]*)} // did not give me any error
}
but in either case, I was unable to see fields tag in the stdout (Is the fields tag updated only if the grok parsing succeeds?)
I performed this test on Windows 10 with "File input plugin". Are there any chances that there can be any problems with EOL characters or with File opening or closing?
Unlikely.
match=>{"message",%{NUMBER}} // This gave me _grokparefailure
Always surround strings with double quotes.
but in either case, I was unable to see fields tag in the stdout (Is the fields tag updated only if the grok parsing succeeds?)
config2:
grok {
match => { "@message" => "%{NUMBER:data}"}
}
output
{
"path" => "C:\Users\xyz\Desktop\Demo\WriteText.txt",
"@timestamp" => 2017-06-20T16:22:56.167Z,
"@version" => "1",
"host" => "ABC",
"message" => "789",
"tags" => [
[0] "_grokparsefailure"
]
}
// I am getting parse error for simple number input. So I am wondering If the problem is with windows .txt file and encoding or something because grok is able to parse as GREEDYDATA but not as NUMBER. and there are no field tags in both the outputs.
Upon using --debug flag I found this I donot know if it is useful or not:
_globbed_files: C:\Users\xyz\Desktop\Demo\WriteText.txt: glob is: []
_globbed_files: C:\Users\xyz\Desktop\Demo\WriteText.txt: glob is: ["C:\Users\xyz\Desktop\Demo\WriteText.txt"] because glob did not work
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.