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

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...