Splunk Search
Highlighted

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

SplunkTrust
SplunkTrust

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
Highlighted

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

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
Highlighted

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

SplunkTrust
SplunkTrust

Thanks for the reply 🙂

0 Karma
Highlighted

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

SplunkTrust
SplunkTrust

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