Splunk Search

Extract first 3 lines of raw logs and group

alex5441
Explorer

Hi,

My current query for splunk dashboard is as:

........| eval ErrorMsg=_raw | stats count by Application, ErrorMsg | sort -count | table count, Application, ErrorMsg

My able looks like this:

countApplicationErrorMsg
5abc

{"severity" : "ERROR", "exception" : "xyz abc asd......."........"time" : "12:00:00"><there are mutiple key value pairs with data in multiple lines>........}

10abc{"severity" : "ERROR", "exception" : "xyz abc asd......."........."time" : "12:01:00"<there are mutiple key value pairs with data in multiple lines>........}

 

How can I get table like this:

15abc"exception" : "xyz abc asd 
Labels (3)
0 Karma
1 Solution

manjunathmeti
SplunkTrust
SplunkTrust

Try this:

... | rex "exception\"\s?:\s?\"(?<ErrorMsg>[^\"]+)\"" | stats count by Application, ErrorMsg | sort -count | table count, Application, ErrorMsg

View solution in original post

scelikok
SplunkTrust
SplunkTrust

Hi @alex5441,

Please try below;

| rex "exception\"\s:\s\"(?<ErrorMsg>.*?)\""
| stats count by Application ErrorMsg 
| sort -count 
| table count, Application, ErrorMsg
If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

manjunathmeti
SplunkTrust
SplunkTrust

hi @alex5441,
You can extract the values for the field ErrorMsg using rex command.

 

........| rex "(?<ErrorMsg>\"exception\"\s:\s\"\w+\s\w+\w\s\w+)" | stats count by Application, ErrorMsg | sort -count | table count, Application, ErrorMsg

 

 

If this reply helps you, a like would be appreciated.

0 Karma

alex5441
Explorer

Hi @manjunathmeti 

Thanks for your reply  but Nothing changed on table.

0 Karma

manjunathmeti
SplunkTrust
SplunkTrust

I updated my answer, check now.

0 Karma

alex5441
Explorer

Hi manjunathmet,

Nothing changed agian. However I think if I get everything extracted value of exception Key that would suffice my requirement. 

{"Severity": "ERROR", "exception":"..................................", "logger":"....................."}

In above pattern I am able to extract with regex:   exception":"(.*?)"

But I have to use it as rex in my SPL which needs escaping special chars which I am not sure about.

0 Karma

manjunathmeti
SplunkTrust
SplunkTrust

Try this:

... | rex "exception\"\s?:\s?\"(?<ErrorMsg>[^\"]+)\"" | stats count by Application, ErrorMsg | sort -count | table count, Application, ErrorMsg
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...