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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...