Splunk Search

How to extract value from search response which has a text plus json?

aliosa
Loves-to-Learn Lots

Hello

I am beginner with Splunk.
I made a query and my search result is like 

 

 

text1 text2 text3 response: {
   "status":"UP",
   "object1":{
      "field1":"name1",
      "status":"UP"
   },
   "object2":{
      "field2":"name2",
      "status":"UP"
   },
   "object3":{
      "object4":{
         "field4":"name4",
         "status":"UP"
      },
      "object5":{
         "field5":"name5",
         "status":"UP"
      },
      "status":"UP"
   },
   "object6":{
      "field6":"name6",
      "status":"UP"
   }
}

 

 

I want to obtain the value for object3.status for a column of table.
How to do this ?
With rex field=_raw or spath ?

Thank you in advance.

Labels (1)
0 Karma

aliosa
Loves-to-Learn Lots

Hello
That json come in search response in multiple lines.
This is not working for me 

rex "response: (?<response>.*)"
because response is "{".

Maybe rex should ignore new line characters (\n) to solve this situation.

and response would be all json {....} 

 

0 Karma

aliosa
Loves-to-Learn Lots

Hello
I use 

| rex "response: (?s)(?<response>.*)"
| spath input=response object3{}.status output=status
| table response, status
and it  works.

Any better idea ?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I have updated my response.

If it works, this is probably the easiest way to do it. Any other method is likely to be more complex.

0 Karma

aliosa
Loves-to-Learn Lots

ok

thank you.

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

 

| rex "response: (?s)(?<response>.*)"
| spath input=response object3.status output=status
| table status

 

0 Karma
Get Updates on the Splunk Community!

Fall Into Learning with New Splunk Education Courses

Every month, Splunk Education releases new courses to help you branch out, strengthen your data science roots, ...

Super Optimize your Splunk Stats Searches: Unlocking the Power of tstats, TERM, and ...

By Martin Hettervik, Senior Consultant and Team Leader at Accelerate at Iver, Splunk MVPThe stats command is ...

How Splunk Observability Cloud Prevented a Major Payment Crisis in Minutes

Your bank's payment processing system is humming along during a busy afternoon, handling millions in hourly ...