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
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...