Getting Data In

Event Splitting on Nested JSON

JakeInfoSec
Explorer

I have JSON files which I am trying to event split as the JSON contains multiple events within each log. Here is an example of what the log would look like.

 

 

{
  "vulnerability": [
    {
      "event": {
        "sub1": {
          "complexity": "LOW"
        },
        "sub2": {
          "complexity": "LOW"
        }
      },
      "id": "test",
      "description": "test",
      "state": "No Known",
      "risk_rating": "LOW",
      "sources": [
        {
          "date": "test"
        }
      ],
      "additional_info": [
        {
          "test": "test"
        }
      ],
      "was_edited": false
    },
    {
      "event": {
        "sub1": {
          "complexity": "LOW"
        },
        "sub2": {
          "complexity": "LOW"
        }
      },
      "id": "test",
      "description": "test",
      "state": "No Known",
      "risk_rating": "LOW",
      "sources": [
        {
          "date": "test"
        }
      ],
      "additional_info": [
        {
          "test": "test"
        }
      ],
      "was_edited": false
    }
  ],
  "next": "test",
  "total_count": 109465
}

 

 

 In this example there would be two separate events that I need extracted out. I am essentially trying to pull out the event1 and event2 nests. Each log should have this same exact JSON format but there could be any number of events included in them. 

First event

 

 

    {
      "event": {
        "sub1": {
          "complexity": "LOW"
        },
        "sub2": {
          "complexity": "LOW"
        }
      },
      "id": "test",
      "description": "test",
      "state": "No Known",
      "risk_rating": "LOW",
      "sources": [
        {
          "date": "test"
        }
      ],
      "additional_info": [
        {
          "test": "test"
        }
      ],
      "was_edited": false
    }

 

 

Second event

 

    {
      "event": {
        "sub1": {
          "complexity": "LOW"
        },
        "sub2": {
          "complexity": "LOW"
        }
      },
      "id": "test",
      "description": "test",
      "state": "No Known",
      "risk_rating": "LOW",
      "sources": [
        {
          "date": "test"
        }
      ],
      "additional_info": [
        {
          "test": "test"
        }
      ],
      "was_edited": false
    }

 

 

 

I also want to exclude the opening 

 

 

{
  "vulnerability": [

 

 

and closing 

 

 

  ],
  "next": "test",
  "total_count": 109465
}

 

 

 portions of the log files.

 

Am I missing something on how to set this sourcetype up? I have the following currently but that does not seem to be working

LINE_BREAKER = \{(\r+|\n+|\t+|\s+)"event":

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this

LINE_BREAKER = ([\r\n]+)\{[\s\S]+?event\d
SEDCMD-stripStart = s/\{[\s\S]+?"vulnerability":\s\[//
SEDCMD-stripEnd = s/\],[\s\S]+?"next": .*//

The [\s\S]+? construct usually works best at matching embedded newlines.

---
If this reply helps you, Karma would be appreciated.
0 Karma

PickleRick
SplunkTrust
SplunkTrust

Are you sure it will work with multiline events? I'm not 100% sure which regex flags are on with SEDCMD

0 Karma

JakeInfoSec
Explorer

Yeah I tried out the LINE_BREAKER provided above but didn't seem to have any luck. No matter what I have tried I haven't been able to get it working as hoped. I think you're right in that the layout as is is just bad so I'm going to go back to the drawing board and try to change how the logs are formatted prior to hitting Splunk. 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

This is simply bad data (at least from Splunk's point of view).

Even if you managed to break it into events (but I gotta honestly say that I see no way to reliably make sure you break in proper places and only in those places; manipulating structured data with just regexes is simply not reliable because regexes are not structure-aware), you'll still have those headers and footers (attached to an end of another event).

Also resulting events would have inconsistent contents - one event would have "event1" field, another would be "event2".

The best solution here would be to process your data and split before pushing it to Splunk.

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...