Splunk Search

How to access the last log item in array

graziaedu
Explorer

I have this log

{ [-]
   duration3005
   finishTime2021-08-25T15:47:26.838196
   loggersplunk
   startTime2021-08-25T15:47:23.832269
   stepTransitionDuration: [ [+]
   ]

   traceSteps: [ [-]
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     { [+]
     }
     [-]
       logTypeinfo
       messageResponse
       res: { [-]
         httpStatus400
       }

       timestamp2021-08-25T15:47:26.838195
       titleResponse
     }
   ]

   xrayTraceId:

}

 

How can i access only the last item (in bold letter)?

I tried to access with mvindex but return blank results.

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| spath path=traceSteps{} output=traceSteps
| eval lasttrace=mvindex(traceSteps,-1)
| spath input=lasttrace

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| spath path=traceSteps{} output=traceSteps
| eval lasttrace=mvindex(traceSteps,-1)
| spath input=lasttrace
0 Karma

graziaedu
Explorer

Thanks @ITWhisperer 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...