0
votes

Please help me to create grok pattern for below log:

{ "sysdate":"[08/Jun/2019:00:00:12 -0400]", "site":"abcd.net", "host":"hostnam.net", "method":"POST", "request":"/services/path", "querystring":"", "port":"4123", "username":"-", "cookie":"0000k1cgki:1f:1bv8tat", "coauthsessionid":"-", "clienthost":"44.25.14.241", "httpversion":"HTTP/1.1", "useragent":"-", "referer":"-", "responsestatus":"200", "subresponse":"0", "win32status":"0", "sbytes":"799", "cbytes":"0", "timetaken":"3595" }
1
You can directly send json format to Logstash or ES. elastic.co/guide/en/logstash/current/plugins-filters-json.htmlSiddharth Kumar
what are you trying to do with grok pattern? Any specific field or value you want to grab or just every field that is there? the data seems in JSON format alreadyJBone

1 Answers

1
votes

Try this:

INPUT:

{"sysdate":"[08/Jun/2019:00:00:12 -0400]","site":"abcd.net","host":"hostnam.net", "method":"POST", "request":"/services/path", "querystring":"", "port":"4123", "username":"-", "cookie":"0000k1cgki:1f:1bv8tat", "coauthsessionid":"-", "clienthost":"44.25.14.241", "httpversion":"HTTP/1.1", "useragent":"-", "referer":"-", "responsestatus":"200", "subresponse":"0", "win32status":"0", "sbytes":"799", "cbytes":"0", "timetaken":"3595"}

GROK PATTERN:

\{"sysdate":"%{GREEDYDATA:sysdate}","site":"%{GREEDYDATA:site}","host":"%{GREEDYDATA:host}", "method":"%{GREEDYDATA:method}", "request":"%{GREEDYDATA:request}", "querystring":"%{GREEDYDATA:querystring}", "port":"%{GREEDYDATA:port}", "username":"%{GREEDYDATA:username}", "cookie":"%{GREEDYDATA:cookie}", "coauthsessionid":"%{GREEDYDATA:coauthsessionid}", "clienthost":"%{GREEDYDATA:clienthost}", "httpversion":"%{GREEDYDATA:httpversion}", "useragent":"%{GREEDYDATA:useragent}", "referer":"%{GREEDYDATA:referer}", "responsestatus":"%{GREEDYDATA:responsestatus}", "subresponse":"%{GREEDYDATA:subresponse}", "win32status":"%{GREEDYDATA:win32status}", "sbytes":"%{GREEDYDATA:sbytes}", "cbytes":"%{GREEDYDATA:cbytes}", "timetaken":"%{GREEDYDATA:timetaken}"\}

OUTPUT:

{
  "sysdate": [
    [
      "[08/Jun/2019:00:00:12 -0400]"
    ]
  ],
  "site": [
    [
      "abcd.net"
    ]
  ],
  "host": [
    [
      "hostnam.net"
    ]
  ],
  "method": [
    [
      "POST"
    ]
  ],
  "request": [
    [
      "/services/path"
    ]
  ],
  "querystring": [
    [
      ""
    ]
  ],
  "port": [
    [
      "4123"
    ]
  ],
  "username": [
    [
      "-"
    ]
  ],
  "cookie": [
    [
      "0000k1cgki:1f:1bv8tat"
    ]
  ],
  "coauthsessionid": [
    [
      "-"
    ]
  ],
  "clienthost": [
    [
      "44.25.14.241"
    ]
  ],
  "httpversion": [
    [
      "HTTP/1.1"
    ]
  ],
  "useragent": [
    [
      "-"
    ]
  ],
  "referer": [
    [
      "-"
    ]
  ],
  "responsestatus": [
    [
      "200"
    ]
  ],
  "subresponse": [
    [
      "0"
    ]
  ],
  "win32status": [
    [
      "0"
    ]
  ],
  "sbytes": [
    [
      "799"
    ]
  ],
  "cbytes": [
    [
      "0"
    ]
  ],
  "timetaken": [
    [
      "3595"
    ]
  ]
}

You can use this for grok writing.