Reporting

Help with regular expression to extract fields

vineela
Path Finder

I need to write regular expression to extract few fields in this, but not able to figure this out. Can you please help me on the same.

X-Response-Timestamp: 2022-08-24T07:27:26.150Z x-amzn-Remapped-Connection: close ... 4 lines omitted ... X-Amzn-Trace-Id: Root=1-6305d2de-69ec840431ff21182b4a9f68 Content-Type: application/json {"code":"APS.MPI.2019","severity":"FATL","text":"Invalid Request","user_message":"Request id has already used."}


Above is the whole log. I need to extract code,severity and message. I cant able t understand the format and fetch.

Labels (1)
Tags (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @vineela,

this seems to be a Json log, so you could try to use the spath command (https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath).

If anyway you want to use a regex, you could try something like this:

| rex "\"code\":\"(?<code>[^\"]+)\",\"severity\":\"(?<severity>[^\"]+)\".*\"user_message\":\"(?<user_message>[^\"]+)\""

that you can test at https://regex101.com/r/8Ggre7/1

Ciao.

Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @vineela,

this seems to be a Json log, so you could try to use the spath command (https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath).

If anyway you want to use a regex, you could try something like this:

| rex "\"code\":\"(?<code>[^\"]+)\",\"severity\":\"(?<severity>[^\"]+)\".*\"user_message\":\"(?<user_message>[^\"]+)\""

that you can test at https://regex101.com/r/8Ggre7/1

Ciao.

Giuseppe

0 Karma

vineela
Path Finder

Hi gcusello,

                 It is working and thanks for introducing new command as well to me..I will try to check documentation for spath command.

Appreciate you for quick response

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @vineela,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...