Splunk Dev

How do i extract my field using rex;

Gaya852635
Loves-to-Learn

Hi

How do i extract my field using rex;

Below is the sample log:
"{"xxxx":{"zzzz":"405","statusMessage":"Added","zzzzzzz":false}}",

Tags (1)
0 Karma

jodyfsu
Path Finder

Here is what I came up with:
| rex (^{{1}"{1}(?\w{4})"{1}:{1}{{1}"{1}(?\w{4})"{1}:{1}"{1}(?\d{3})"{1},{1}"{1}(?\w*)"{1}:{1}"{1}(?\w*)"{1},{1}"{1}(?\w*)"{1}:{1}(?\w*)}{2})

0 Karma

jodyfsu
Path Finder

Looks like some was escaped out:
"| rex (^{{1}"{1}(?\w{4})"{1}:{1}{{1}"{1}(?\w{4})"{1}:{1}"{1}(?\d{3})"{1},{1}"{1}(?\w*)"{1}:{1}"{1}(?\w*)"{1},{1}"{1}(?\w*)"{1}:{1}(?\w*)}{2})"

0 Karma

jodyfsu
Path Finder

my named capture groups keep getting dropped when I post.
| rex (^{{1}"{1}(?named capture group\w{4})"{1}:{1}{{1}"{1}(?named capture group\w{4})"{1}:{1}"{1}(?named capture group\d{3})"{1},{1}"{1}(?named capture group\w*)"{1}:{1}"{1}(?named capture group\w*)"{1},{1}"{1}(?named capture group\w*)"{1}:{1}(?named capture group\w*)}{2}

0 Karma

DalJeanis
Legend

@jodyfsu - you can mark your code using any of three strategies, to avoid html-like items being stripped out or interpreted as formatting.

1) For any amount of text, highlight the text and press the "mark code" button (101 010). that button works better for me on Chrome.

2) For lots of code text, put at least four spaces in front of the first non-whitespace character on each line. Make sure there is at least one completely empty line before the first code line.

3) For small pieces of code, use backticks (also called grave accents) before and after the code. That character () is found under the tilde~to the left of the1` on an American keyboard.

0 Karma

jodyfsu
Path Finder

Thank you.

0 Karma

skoelpin
SplunkTrust
SplunkTrust

This doesn't capture anything and also seems overkill.. I would suggest adding sample data before and after that you want to extract and one of us will give you a much cleaner regex

0 Karma

jodyfsu
Path Finder
"| rex (^{{1}"{1}(?<f1>\w{4})"{1}:{1}{{1}"{1}(?<f2>\w{4})"{1}:{1}"{1}(?<f3>\d{3})"{1},{1}"{1}(?<f4>\w*)"{1}:{1}"{1}(?<f5>\w*)"{1},{1}"{1}(?<f6>\w*)"{1}:{1}(?<f7>\w*)}{2})"
0 Karma

skoelpin
SplunkTrust
SplunkTrust

So you want to extract "{"xxxx":{"zzzz":"405","statusMessage":"Added","zzzzzzz":false}}", from your log and name it OP_FRM_SRC_SYS?

Can you provide . larger sample size of characters/test before and after the field you want to extract?

0 Karma

sbbadri
Motivator

@Gaya852635

try this in props.conf

[json_embedded]
REGEX = "(\w+)"."(\S+?)"
FORMAT = $1::$2

0 Karma

jodyfsu
Path Finder

Which field are you trying to pull out?

Gaya852635
Loves-to-Learn

This is the fieldname:OP_FRM_SRC_SYS

OP_FRM_SRC_SYS="{"xxxx":{"zzzz":"405","statusMessage":"Added","zzzzzzz":false}}",

0 Karma

jodyfsu
Path Finder

I am a little confused so please help me understand. So this is in the log:
"{"xxxx":{"zzzz":"405","statusMessage":"Added","zzzzzzz":false}}"..... right?

Which field in the log are you trying to pull out? And are you wanting it named OP_FRM_SRC_SYS.

Please let me know what I am not following.

Gaya852635
Loves-to-Learn

complete field "{"xxxx":{"zzzz":"405","statusMessage":"Added","zzzzzzz":false}}"as a fieldvalue into the fieldname OP_FRM_SRC_SYS.

0 Karma

jodyfsu
Path Finder

Ah, ok.. I will see if I can figure this out 🙂

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...