Splunk Search

How to filter first array element?

andreaantonioni
Observer

My data is something like this:

 

stackTrace: [
{
   inProject: false,
   file: "/path/to/file.c"
},
{
   inProject: true,
   file: "/path/to/file.c"
}, 
{
   inProject: false,
   file: "/path/to/file.c"
}
]

 

  I'd like to get the list of events where the first element that has inProject=true contains "file.c" in file.

Labels (2)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

Well, the wording here is a little tricky because if reading your request literarily, something like this:

stackTrace: [
{
   inProject: true,
   file: "/path/to/otherfile.c"
},
{
   inProject: true,
   file: "/path/to/file.c"
}
]

Should not match. (Bonus question about the filename matching but i suppose you want the literal "file.c" as whole filename, so the "otherfile.c" is something you don't want. Otherwise of course you can adjust the example accordingly.

0 Karma

somesoni2
Revered Legend

If your data is indexed and parsed correctly (as valid json element), something like this should work.

Your current search which includes field with name stackTrace{}.inProject and stackTrace{}.file
| where mvindex('stackTrace{}.inProject',0)="false" AND like('stackTrace{}.inProject',"%file.c")

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| spath stackTrace{} output=stackTrace
| mvexpand stackTrace
| spath input=stackTrace
| where inProject="true" AND match(file,"file\.c")
0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

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