Splunk Search

Extraction of a field inside Json data

splunklearner
Communicator

Please extract User-Agent field from the below Json event .

httpMessage{ [-]
     bytes2
     hostrbwm-api.sony.co.uk
     methodGET
     path/kong/originations-loans-uk-orchestration-prod-proxy/v24/status
     port443
     protocolHTTP/1.1
     requestHeadersContent-Type: application/json X-SONY-Locale: en_GB X-SONY-Chnl-CountryCode: GB X-SONY-Chnl-Group-Member: HRFB X-SONY-Channel-Id: WEB Cookie: dspSession=hzxVP-NKKzZIN0wfzk85UD0ji7I.*AAJTSQACMDIAAlNLABxvOTRoWElJS2FEU0wrNlMxdTByMGtGN2JYM289AAR0eXBlAANDVFMAAlMxAAI0NQ..* Accept: */* User-Agent: node-fetch/1.0 ( https://github.com/bitn/node-fetch) Accept-Encoding: gzip,deflate Host: rbwm-api.sony.co.uk Connection: close remove-dup-edge-ctrl-headers-rollout-enabled: 1

httpMessage.requestHeaders field values are extracting but only want User-Agent field and values to be extracted from all values. Please help me with this.
 
Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| rex field=httpMessage.requestHeaders "User-Agent: (?<useragent>.*?)\\r\\n"

View solution in original post

0 Karma

splunklearner
Communicator

thanks

0 Karma

livehybrid
Super Champion

Hi @splunklearner 

Try the following:

| rex field=requestHeaders "User-Agent: (?<useragent>.*?)(?=\s+\w+-?[\w-]*: )"

livehybrid_0-1750797591754.png

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma

richgalloway
SplunkTrust
SplunkTrust

What have you tried so far?  What were the results?

---
If this reply helps you, Karma would be appreciated.
0 Karma

splunklearner
Communicator

I used spath command but didn't work.

0 Karma

splunklearner
Communicator

This is the _raw data.

 

"requestHeaders":"X-sony-PSD2-CountryCode: GB\r\nX-sony-Request-Correlation-Id: 50977be2-f86c-451a-b318-50b4dfc46b4a\r\nX-sony-Secondary-Id: 1614874131\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36\r\nX-sony-Channel-Id: OPENBANK\r\nX-sony-TPP-Journey: AISP\r\nX-sony-Locale: GB\r\nToken_Type: ACCESS_TOKEN\r\nX-sony-SoR-CountryCode: GB\r\nx-fapi-interaction-id: 80c0c1c4-ab24-4cc3-9169-4ef8ecfa90ba\r\nX-sony-Tpp-Name: TrueLayer Limited\r\nContent-Type: application/json\r\nX-sony-Global-Channel-Id: OPENBANK\r\nAccept: application/json\r\nX-sony-Client-Id: 5ec4d197-f5f9-432d-8201-e55618ba970e\r\nX-sony-Chnl-CountryCode: GB\r\nX-sony-Chnl-Group-Member: HRFB\r\nX-sony-Tpp-Id: 001580000103UAAAA2\r\nX-sony-Session-Correlation-Id: 4137bff6-c7e2-40f9-a1ca-699f59bcd6ed\r\nX-sony-Source-System-Id: 4910787\r\nX-sony-TPP-URL: https://api.ob.sony.co.uk/obie/open-banking/v4.0/aisp/accounts/50l6Ph5oSYfmYYnARlvAWtNimns1vO1Vo-r/t...r\nX-sony-GBGF: RBWM\r\nx-sony-consumer-id: OPENBANKING.OBK_MULESOFT_P\r\nX-sony-Username: arielle1@\r\nX-Forwarded-For: 176.34.193.116\r\nX-sony-Client-Name: TrueLayer\r\nX-sony-Software-Id: gdce9LdcLmKHv2MoEtKdPe\r\nX-Amzn-Trace-Id: Root=1-685ae0f4-a3640d152af9aa6aa7092caa;Sampled=0\r\nHost: rbwm-api.sony.co.uk\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip,deflate\r\nremove-dup-edge-ctrl-headers-rollout-enabled: 1\r\n",

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| rex field=httpMessage.requestHeaders "User-Agent: (?<useragent>.*?)\\r\\n"
0 Karma
Get Updates on the Splunk Community!

Deep Dive into Federated Analytics: Unlocking the Full Power of Your Security Data

In today’s complex digital landscape, security teams face increasing pressure to protect sprawling data across ...

Your summer travels continue with new course releases

Summer in the Northern hemisphere is in full swing, and is often a time to travel and explore. If your summer ...

From Alert to Resolution: How Splunk Observability Helps SREs Navigate Critical ...

It's 3:17 AM, and your phone buzzes with an urgent alert. Wire transfer processing times have spiked, and ...