I am facing some issues with parsing a logline.
I Have thousends of loglines and every logline contains a hostname like ABC123DF I Have writen a regex and I want to apply it to the logline and put the hostname in the field "victim" Like this:
add_field => [ "victim", "/[a-z][a-z][a-z][0-9][0-9][0-9].."
I have used the Mutate filter but the result is
victim /[a-z][a-z][a-z][0-9][0-9][0-9]..
I would like to see:
victim ABC123DF
how do I do this?
So in my case the logline is:
2015-10-20 14:45:42,156 [pool-3-thread-1] INFO audit Terminated abc123df from group LLDS2Cassandra [LOCAL] with NetworkCorruption
And in the grok patterns I put the following line:
VICTIM [a-z][a-z][a-z][0-9][0-9][0-9]
.To get the following result:
FIELD: TIMESTAMP VALUE: 2015-10-20 14:45:42,156
FIELD: VICTIM VALUE: abc123df
FIELD:LOGLEVEL
VALUEE:INFO
You don't even need complex regex action to achieve this. You can use several filters to extract fields. In your case, the grok filter is a good choice.
Let's suppose your log lines look like this:
Then a grok filter like this would parse the hostname properly:
You can also use regex inside grok (docs). Example Pattern:
However, I would recommend to avoid regex in grok. It is a better approach to go with the included patterns. Use the grok debugger to find the right patterns for you.
I user this site, http://grokconstructor.appspot.com/do/match#result, to test my regex.
In my mongodb log, I have this text:
For get query and time, in config file, I make this filter:
Use:
after this, you can make: