Splunk Search

Help with Regex to extract values

napoleon182
Explorer

Hello Splunk Ninjas!

I'm new to the group (and to the splunk) and will require your assistance with designing my regex expression.

I need to filter for the value of Message in this sample log line:

 

2022-09-23T13:20:25.765+01:00 [29] WARN  Core.ErrorResponse - {} - Error message being sent to user with Http Status code: BadRequest:
{"Message":"Sorry, only real values are valid in this environment.","UserMessage":null,"Code":64,"Explanation":null,"Resolution":null,"Category":3}

 

I will be interested in extracting value of Message, Code, Resolution and Category,

Any help, much appreciated!

Thanks again

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

as you said, using the table command:

<your_search>
| rex "\{\"Message\":\"(?<Message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"
| table Message Code Explanation Resolution Category

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

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

otherwise, you could use a regex like the following

| rex "\{\"Message\":\"(?<message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"

tha you can test at https://regex101.com/r/3YCPYQ/1

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

as you said, using the table command:

<your_search>
| rex "\{\"Message\":\"(?<Message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"
| table Message Code Explanation Resolution Category

Ciao.

Giuseppe

napoleon182
Explorer

Thank you Guiseppe, thats perfect, many thanks for your assistance!

0 Karma

napoleon182
Explorer

Thank you Giuseppe, how can i now present it in the table? (with using the | table switch)

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Quantify Your Splunk Investment Impact: Introducing Savings Metrics to Value Insights

Building on the foundation established in our initial Value Insights releases, we are introducing the Savings ...

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...