Splunk Search

How to extract a field that returns after a line_breaker

jorambokma
Explorer

Hello,

We are trying to split a nested json message into seperated events.
As we not wish to use the spath function it would be nice to split the events;
Our biggest challange right now is that we want to add the kId field in every event.

Example of the json;

{
    "kId": 47,
    "mId": 96,
    "resultStatus": "OK",
    "results": [{
        "creationDate": 1560509581000,
        "name": "test",
        "resultStatus": "OK",
        "duration": 0.858
    }, {
        "creationDate": 1560509581000,
        "name": "test2",
        "resultStatus": "OK",
        "duration": 0.858
    }]
}

we managed to get seperated events by using the following configurations:

props.conf
[measurements]
TRANSFORMS-kId = extract_kId
LINE_BREAKER = (},){|([){|(])}
SHOULD_LINEMERGE = false

transforms.conf
[extract_kId]
REGEX = kId[\"]:[,]
FORMAT = kId::$1
WRITE_META = true

events now look like this;

{"creationDate":1560509581000,"name":"test","resultStatus":"OK","duration":0.858}
{"creationDate":1560509581000,"name":"test2","resultStatus":"OK","duration":0.858}

How can we add the kId into this events?

Thanks in advance!

0 Karma
1 Solution

FrankVl
Ultra Champion

I don't think you can with Splunk. Event breaking is one of the first things that happens, so even if you could come up with a transforms or so to copy that kld to all the 'subsections', that all happens after line breaking, so the information is no longer available since Splunk processes each event on its own without knowledge of previous events.

You'll probably have to look at writing a script that pre-processes the logs before the are read by Splunk.

View solution in original post

FrankVl
Ultra Champion

I don't think you can with Splunk. Event breaking is one of the first things that happens, so even if you could come up with a transforms or so to copy that kld to all the 'subsections', that all happens after line breaking, so the information is no longer available since Splunk processes each event on its own without knowledge of previous events.

You'll probably have to look at writing a script that pre-processes the logs before the are read by Splunk.

jorambokma
Explorer

Thanks for your answer. Would sedcmd an option? Is it possible to use sedcmd with variables?

0 Karma

FrankVl
Ultra Champion

sedcmd also happens after event breaking. But anyway that is in essence just a search&replace and while you can use the /g flag to repeat the sedcmd, you cannot carry that kId found in the first part forward to later matches.

I think the only solution (other than preprocessing) would be to ingest the event as a whole and process it using SPL (using a combination of spath and multivalue tricks).

0 Karma

jorambokma
Explorer

Thanks. We will investigate our preprocessing options.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

Ready to make your IT operations smarter and more efficient? Discover how to automate Splunk alerts with Red ...