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

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...