Splunk Search

Rex Help for fields extraction

sravankaripe
Communicator

Please help me with rex
i have key and value in json format

{"context":{

"sessionID":"1234567890",
"eventSeverity":"Debug",
"msgType":"REQUEST",
"appID":"someServices",
"eventID":"START","msgPayload":{"inboundMsg":{"msgContentType":"{"idtypes":["ABCDE","ABC"],"userName":"someName"}"}}}}
how to retrive fields out of it.

Tags (1)
0 Karma
1 Solution

skoelpin
SplunkTrust
SplunkTrust

Which value do you want to extract?

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this. The rex-sed command is requires as your data seems to have extra double quotes making it not pure json.

your current search which includes field _raw | rex mode=sed "s/\"{/{/g" | spath

somesoni2
Revered Legend

Is this _raw or a field?

0 Karma

sravankaripe
Communicator

Yes,this is _raw field

0 Karma

skoelpin
SplunkTrust
SplunkTrust

Which value do you want to extract?

0 Karma

sravankaripe
Communicator

sessionID,eventSeverity,msgType,appID,eventID,msgPayload,inboundMsg,msgContentType,idtypes,userName

0 Karma

skoelpin
SplunkTrust
SplunkTrust

I'd recommend kv_mode=json

But if you want to see how it's done then here ya go

... | rex sessionID\"\:\"(?<SessionID>\d+)
... | rex eventSeverity\"\:\"(?<EventSeverity>\w+)
... | rex msgType\"\:\"(?<msgType>\w+)
... | rex appID\"\:\"(?<AppID>\w+)
... | rex eventID\"\:\"(?<EventID>\w+)
0 Karma

sravankaripe
Communicator

"idtypes":["ABCDE","XYZ"]

how to write for this

0 Karma

dbcase
Motivator

what do you want to extract? ABCDE or XYZ, or the whole string ABCDE,XYZ?

0 Karma

sravankaripe
Communicator

["ABCDE","XYZ"]

entire this value

0 Karma

skoelpin
SplunkTrust
SplunkTrust

Here ya go. If this answered your question, can you please accept it?

idtypes":\["(?<Name1>\w+)"\,"(?<Name2>\w+)

0 Karma

dbcase
Motivator

try this:

"idtypes":(?<idtypes>\S+)[,]
0 Karma

sjalexander
Path Finder

if you can add
KV_MODE = json
to your props.conf for this sourcetype it's going to save you a lot of trouble (extraction will be automatic).

rex is most useful when automatic extraction fails; try the builtin functionality first.

more details available here:
https://answers.splunk.com/answers/124406/extracting-fields-from-json-file-format.html

0 Karma

sravankaripe
Communicator

I need during search time.

0 Karma

sjalexander
Path Finder

understood. If this is something you're going to do on an ongoing basis, it's still a very good idea to get this stuff indexed in a usable manner instead of relying on searchtime hacks. If it's a one-off, carry on 🙂

Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...