Greetings,
My logs are of the format
2017-12-08 01:42:23,658 app="capture", level=ERROR, thread=play-thread-5, logger=play, userId="client:release", reqAction="GET", reqUrl="/api/labels", message="
console.App.html action not found
pls help me in breaking them with expression
as i want timestamp,capture,loglevel
I have applied %{TIMESTAMP_ISO8601:timestamp} %{WORD:action}
Use ^%{TIMESTAMP_ISO8601:timestamp} %{GREEDYDATA:kv} to get a timestamp and the key/value pairs into one field each, then use a kv filter to parse the kv field that you get from the grok filter.
The Description section in the documentation contains an example and an explanation. In your case you'll have to adjust the field_split option since your fields are separated by ", ".
For that kind of message you need a different grok expression. A single grok filter can list multiple expressions that will be tried in order, so you can have one expression that attempts to match a general message with a log level and one that extract key/value pairs.
@magnusbaeck thankyou, yes I filtered the logs but now i am facing a issue as whenever i run my logstash with the config file which is
input {
beats {
port => 5044
}
}
filter {
if [type] == "plateu" {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp} %{GREEDYDATA:kv}"}
}
date {
match => ["timestamp", "yyyy-MM-dd HH:mm:ss.SSS", "ISO8601"]
timezone => "UTC"
}
}
kv {
field_split => ",?"
}
else if [type] == "manage" {
grok {
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp} [%{LOGLEVEL:level} ]"}
}
date {
match => ["timestamp", "yyyy-MM-dd HH:mm:ss.SSS", "ISO8601"]
timezone => "UTC"
}
}
}
output {
if [type] == "plateu" {
elasticsearch {
hosts => "localhost:9200"
index => "denmark1"
}
}
else if [type] == "hill" {
elasticsearch {
hosts => "localhost:9200"
index => "denmark1"
}
}
stdout {}
}
when i didnt use kv its working fine but when i am using it i am facing a issue it says
[2017-12-14T16:54:59,871][ERROR][logstash.agent ] Cannot create pipeline {:reason=>"Expected one of #, { at line 19, column 7 (byte 374) after filter {\n\tif [type] == "plateu" {\n\t grok {\n\t match => {"message" => "%{TIMESTAMP_ISO8601:timestamp} %{GREEDYDATA:kv}"}\n\t }\n date {\n\t match => ["timestamp", "yyyy-MM-dd HH:mm:ss.SSS", "ISO8601"]\n\t timezone => "UTC"\n\t }\n }\n kv {\n field_split => ",?"\n }\n\telse "}
I'm a bit surprised that the ISO8601 pattern isn't able to parse the timestamp field, but the "yyyy-MM-dd HH:mm:ss.SSS" pattern is obviously wrong since timestamp doesn't have millisecond resolution.
@magnusbaeck Thankyou for the reply
I am having two different timestamp format for a no of files
for eg
09:41:58,932 WARN ~ Tried to associate with unreachable remote address . Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters.
2016-12-14 09:29:37,750 [WARN ] ~ Tried to associate with unreachable remote address. Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters.
So the date is sometimes missing? That's going to be a problem. Logstash will default to today's date when you only have the time so if you're processing the logs in real time you'll be okay most of the time.
As for how to parse it, both the grok and date filters support multiple expressions that'll get tried in order. You need one set of expressions for date+time and one with time only.
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.