Splunk Search

How to split JSON array into Multiple events at Index Time?

mayurr98
Super Champion

I have an event :

{
    "local": [
        {
            "display_name": "juniper0",
            "tenant": null,
            "created": "2019-03-29",
            "local_context_data": {
                "ntp": {
                    "peers": [
                        "192.168.10.15",
                        "192.168.10.16"
                    ]
                }
            },
            "serial": "124334",
            "asset_tag": null,
            "site": {
                "id": 1,
                "name": "TestSite",
                "slug": "testsite"
            },
            "virtual_chassis": null,
            "primary_ip4": {
                "id": 7,
                "address": "192.37.28.78/24",
                "family": 4
            },
            "cluster": null,
            "tags": [],
            "last_updated": "2019-04-01T09:41:41.633296Z",
            "vc_position": null,
            "primary_ip": {
                "id": 7,
                "address": "192.37.28.78/24",
                "family": 4
            },
            "device_type": {
                "id": 1,
                "display_name": "Juniper test",
                "manufacturer": {
                    "id": 5,
                    "name": "Juniper",
                    "slug": "juniper"
                },
                "slug": "test",
                "model": "test"
            },
            "primary_ip6": null,
            "parent_device": null,
            "face": null,
            "device_role": {
                "id": 3,
                "name": "Switch",
                "slug": "switch"
            },
            "comments": "",
            "platform": null,
            "name": "juniper0",
            "id": 8,
            "status": {
                "value": 1,
                "label": "Active"
            },
            "position": null,
            "custom_fields": {},
            "rack": null,
            "vc_priority": null
        },
        {
            "display_name": "juniper1",
            "tenant": null,
            "created": "2019-04-02",
            "local_context_data": null,
            "serial": "",
            "asset_tag": null,
            "site": {
                "id": 1,
                "name": "TestSite",
                "slug": "testsite"
            },
            "virtual_chassis": null,
            "primary_ip4": null,
            "cluster": null,
            "tags": [],
            "last_updated": "2019-04-02T18:08:16.222025Z",
            "vc_position": null,
            "primary_ip": null,
            "device_type": {
                "id": 1,
                "display_name": "Juniper test",
                "manufacturer": {
                    "id": 5,
                    "name": "Juniper",
                    "slug": "juniper"
                },
                "slug": "test",
                "model": "test"
            },
            "primary_ip6": null,
            "parent_device": null,
            "face": null,
            "device_role": {
                "id": 6,
                "name": "Firewall",
                "slug": "firewall"
            },
            "comments": "",
            "platform": null,
            "name": "juniper1",
            "id": 9,
            "status": {
                "value": 1,
                "label": "Active"
            },
            "position": null,
            "custom_fields": {},
            "rack": null,
            "vc_priority": null
        }
    ]
}

I want this event to be split into 2 events such as :

1st Event

{
             "display_name": "juniper0",
             "tenant": null,
             "created": "2019-03-29",
             "local_context_data": {
                 "ntp": {
                     "peers": [
                         "192.168.10.15",
                         "192.168.10.16"
                     ]
                 }
             },
             "serial": "124334",
             "asset_tag": null,
             "site": {
                 "id": 1,
                 "name": "TestSite",
                 "slug": "testsite"
             },
             "virtual_chassis": null,
             "primary_ip4": {
                 "id": 7,
                 "address": "192.37.28.78/24",
                 "family": 4
             },
             "cluster": null,
             "tags": [],
             "last_updated": "2019-04-01T09:41:41.633296Z",
             "vc_position": null,
             "primary_ip": {
                 "id": 7,
                 "address": "192.37.28.78/24",
                 "family": 4
             },
             "device_type": {
                 "id": 1,
                 "display_name": "Juniper test",
                 "manufacturer": {
                     "id": 5,
                     "name": "Juniper",
                     "slug": "juniper"
                 },
                 "slug": "test",
                 "model": "test"
             },
             "primary_ip6": null,
             "parent_device": null,
             "face": null,
             "device_role": {
                 "id": 3,
                 "name": "Switch",
                 "slug": "switch"
             },
             "comments": "",
             "platform": null,
             "name": "juniper0",
             "id": 8,
             "status": {
                 "value": 1,
                 "label": "Active"
             },
             "position": null,
             "custom_fields": {},
             "rack": null,
             "vc_priority": null
         }

2nd Event

{
             "display_name": "juniper1",
             "tenant": null,
             "created": "2019-04-02",
             "local_context_data": null,
             "serial": "",
             "asset_tag": null,
             "site": {
                 "id": 1,
                 "name": "TestSite",
                 "slug": "testsite"
             },
             "virtual_chassis": null,
             "primary_ip4": null,
             "cluster": null,
             "tags": [],
             "last_updated": "2019-04-02T18:08:16.222025Z",
             "vc_position": null,
             "primary_ip": null,
             "device_type": {
                 "id": 1,
                 "display_name": "Juniper test",
                 "manufacturer": {
                     "id": 5,
                     "name": "Juniper",
                     "slug": "juniper"
                 },
                 "slug": "test",
                 "model": "test"
             },
             "primary_ip6": null,
             "parent_device": null,
             "face": null,
             "device_role": {
                 "id": 6,
                 "name": "Firewall",
                 "slug": "firewall"
             },
             "comments": "",
             "platform": null,
             "name": "juniper1",
             "id": 9,
             "status": {
                 "value": 1,
                 "label": "Active"
             },
             "position": null,
             "custom_fields": {},
             "rack": null,
             "vc_priority": null
         }
0 Karma
1 Solution

mayurr98
Super Champion

Solved with the following config:

[sourcetype]
KV_MODE = json
LINE_BREAKER = \}(,\s+)\{
SEDCMD-remove_footer = s/\}\s+\]//g
SEDCMD-remove_header = s/\{\s+\"local\"\:\s+\[//g
SHOULD_LINEMERGE = 0
pulldown_type = 1

View solution in original post

0 Karma

mayurr98
Super Champion

Solved with the following config:

[sourcetype]
KV_MODE = json
LINE_BREAKER = \}(,\s+)\{
SEDCMD-remove_footer = s/\}\s+\]//g
SEDCMD-remove_header = s/\{\s+\"local\"\:\s+\[//g
SHOULD_LINEMERGE = 0
pulldown_type = 1
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@mayurr98

Can you please try below configurations in your props.conf?

[my_stanza]
DATETIME_CONFIG=CURRENT
SHOULD_LINEMERGE=true
NO_BINARY_CHECK=true
LINE_BREAKER=}(\,){
SEDCMD-break=s/({"local": \[)//g
SEDCMD-b=s/]}$//g

mayurr98
Super Champion

Thanks for the reply 🙂

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...