Grok a multi format log file - custom app

Hi there,

So I have a custom application with a log file that have multiple type of lines, normal syslog and also json.

It looks like this:

 2019-03-07T11:29:52+0000 | | [3rdParty] xxxxxxxxxxxx || INFO    | REQUEST | PUT | HEADERS:  Accept-Encoding: gzip, deflate
        M2M-Tracking-Token: xxxxxx
        Content-Length: 2
        Content-Type: application/json
        User-Agent: Zend_Http_Client
        Connection: Keep-Alive
        M2M-Apikey: xxxxxxxx
        X-Forwarded-Proto: https

         BODY:  []
2019-03-07T11:29:52+0000 | | [3rdParty] xxxxxxxxxxxx | xxxxxxx | INFO    | RESPONSE | 200 OK PUT | 32ms | HEADERS:  Content-Type: application/json
        Content-Length: 473
        X-CSRF-Token: None
        X-Tracking-Token: xxxxxxx

         BODY:  {
          "serviceSession": {
            "testID: xxxxxx",

So I configured filebeat to use multiline since I want to "merge" them by timestamp date, otherwise I will get a lot of lines inside message and it`s hard to grok when you have a log with hundred of lines.

multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after 

Now I get in my full length under message so I can play with grok to extract some relevant data.

I have some questions:

  1. Is there a way to mark that BODY: {} as json?
  2. Is there a way to grok through this json part to extract testID field? a find function?
  3. In the first part of the log I have a response time measured in milliseconds, can I extract that as a metric %NUMBER field?

Thanks for your time!

Assuming it is valid JSON (which your example most certainly is not) then you could do that using

    grok { match => { "message" => " \| %{NUMBER:duration:int}ms \| %{DATA} BODY:  %{GREEDYDATA:body}" } }
    json { source => "body" }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.