Splunk Search

Extracting specific parts from _raw logs

DanAlexander
Communicator

Hi All,

Can anyone help me create a regex to extract the bolded parts from the following _raw log, please?

meta sequenceId="182311942"]10000 - [action:"Accept"; ........; origin:"10.111.10.111"; originsicname:"CN=................610;policy_name=High_Trust-1\]"; dst:"192.168.11.01"; log_delay:"1683724684"; layer_name:"Some text"; layer_name:"High_Trust-1 Application"; layer_uuid:"426c8a................."StoneBeat-Control"; src:"192.168.81.62"]

Thank you in advance!

Labels (3)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

if above is true you could try this for all previous fields as own rex. When you’re using separate rex, then the order can change and you could add more fields later.

<your base search>
| rex "action:\"(<?action>[^\"]+)"
| <next rex with another field name> …

r. Ismo

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

It seems that your developers take pains to design a well formatted log.  It would be a waste to use regex for extraction.  Use extract instead.

| extract pairdelim=";" kvdelim=":"

Hope this helps 

DanAlexander
Communicator

Thanks for the update @yuanliu 

Would you please elaborate on the regex waste? 

Not so sure what you have in mind based on your experience.

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

To extract patterns like ":\s*(?<field1>[^;]+)[^:]+(?<field2>[^;]+)" (which is required for that type of data), rex has to scan character by character with an indeterministic presumption.  In comparison, pairdelim=";" kvdelim=":" simply scans for fixed strings ";" and ":", which is computationally less complex. (And less demanding in RAM.)  As @isoutamo said, this does not mean that extract will always be more efficient or any choice will have material impact on performance.  But as a general practice, choose fixed pattern over regex.  The main advantage, of course, is that extract command extracts multiple kv pairs regardless of their order.

isoutamo
SplunkTrust
SplunkTrust

Just replace those all rex statements with this one. This will extract all those kv pairs.

Which option is more efficient can be check by Job Inspector.

cklunck
Path Finder

After the extraction is complete, are you hoping to have fields and field values like the following?

action=Accept

origin=10.111.10.111

layer_name="Some text"

 

0 Karma

DanAlexander
Communicator

Thanks for the reply @cklunck 

Positive, this is what I want to achieve.

 

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

if above is true you could try this for all previous fields as own rex. When you’re using separate rex, then the order can change and you could add more fields later.

<your base search>
| rex "action:\"(<?action>[^\"]+)"
| <next rex with another field name> …

r. Ismo

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...