Splunk Search

multiple case statement not working

samneo
Path Finder

Im working with JSON data and the structure is as per the below

 

data: { [-]
     application: { [+]
     }
     completedAt: 1636133794444
     environments: [ [-]
       { [-]
         id: XNu1-l8oROOOSM5gpoSR0g
       }
       { [-]
         id: _LY0B7VpRq64tHXq7Uy55A
       }
       { [-]
         id: 7KbvgSBMSUSUyAn2hMXSQA
       }
       { [-]
         id: dJ7EuItjSG2M47-zvIvimQ
       }
     ]

 

Now when i use a case function for this like the below:

|eval env = case('data.environments{}.id'=="7KbvgSBMSUSUyAn2hMXSQA", "prd-au", 'data.environments{}.id'=="_LY0B7VpRq64tHXq7Uy55A", "prd-gb")

It only ever brings me back 1 result and thats whatever is placed first in the case function so the above returns prd-au and if i swap the values around then it will return prd-gb. I presume this is something to do with how the JSON data is working with splunk causing it to error out but unsure how to resolve?

any ideas? 

Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You would need to expand the event into multiple events, try something like this

| mvexapnd 'data.environments{}.id'

 

View solution in original post

0 Karma

samneo
Path Finder

thanks @ITWhisperer is there a way round this so i can get all values?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You would need to expand the event into multiple events, try something like this

| mvexapnd 'data.environments{}.id'

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Splunk is working with a pipeline of events - the events in the pipeline include multivalue fields such as data.environments{}.id - the eval case finds a match among the multivalues for the first test hence you get the results you are getting

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Unmerging HTML Tables

[Puzzles] Solve, Learn, Repeat: Unmerging HTML TablesFor a previous puzzle, I needed some sample data, and ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...

AI for AppInspect

We’re excited to announce two new updates to AppInspect designed to save you time and make the app approval ...