Getting Data In

kv_mode=json with combined json / textual loglines

simonroberts2
Engager

I currently index a range of semi-structured log lines which contain a mix of textual and json data. I've recently upgraded to Splunk 4.3.4 and was hoping to use the Splunk 4.3+ "kv_mode=json" feature to avoid maintaining a series of regexes.

Unfortunately, it looks like the json parsing feature expects the entire log line to be json based. Is this correct? If so is it possible to configure the feature to extract based on a field name? Alternatively are there any other suggestions?

Example log line....

[08/Oct/2012:14:31:22.965314 +0100] UHLVqqwQ52oAAGX1I2oAAAAE - [mbet] NOTICE (5): [TIMER] request.run {"init":0.93698501586914,"run":25.791883468628,"uri":"/racing/home","time":31.274080276489}


As a workaround I’ve used a transform to automatically extract any json elements into a “json” field. I then use spath to decode it at search time. It would be great if I could get the json parsed automatically thereby avoiding the spath.

Transform:
REGEX = (?{.+)
SOURCE_KEY - _raw

Example search:
index=web request.run | spath input=json

Tags (2)
1 Solution

dart
Splunk Employee
Splunk Employee

If you're just doing simple key value pairs with json, you can do this using a transform with MV_ADD
[report-json]
REGEX = (?{.+)
[report-json-kv]
SOURCE_KEY = json
REGEX = "(\w+)":"?([^,}"]+)
FORMAT = $1::$2
MV_ADD = true

Referring to it like so in your props:
[sourcetype]
REPORT-json = report-json, report-json-kv

View solution in original post

dart
Splunk Employee
Splunk Employee

If you're just doing simple key value pairs with json, you can do this using a transform with MV_ADD
[report-json]
REGEX = (?{.+)
[report-json-kv]
SOURCE_KEY = json
REGEX = "(\w+)":"?([^,}"]+)
FORMAT = $1::$2
MV_ADD = true

Referring to it like so in your props:
[sourcetype]
REPORT-json = report-json, report-json-kv

pramit46
Contributor

Wow.. this one works like a miracle...Thanks a lot @dart

Just one thing. it totally ignores and removes the timestamp section in the beginning. How can I retain that and still be able to parse the json?

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...