Splunk Search

How to extract error codes coming within single event?

pradeepkm
Explorer

I have an event which contains error reason  codes of failed records . I have to extract these reason codes and get a count of each of these reason codes.

Labels (4)
Tags (1)
0 Karma

venky1544
Builder

Hi @pradeepkm 

is this a multline event  ???  

your search | rex field=_raw "Reason code::(?<Reason_code>[\w+ ]+)" |stats count by Reason_code 

0 Karma

pradeepkm
Explorer

No all reason codes coming in single event .That’s where I have difficulty in gathering stats.

0 Karma

venky1544
Builder

Hi @pradeepkm 

just try the below search 

 index="response" sourcetype="new" | rex field=_raw "Reason code::(?<Reason_code>[\w+ ]+)" max_match=0 |stats count by Reason_code

i just ingested your data and ran the above search query jusr replace your search before the rex command 

venky1544_0-1649157083707.png

venky1544_1-1649157132995.png

if this helps karma points are appreciated 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @pradeepkm,

to extract these error codes you have to create a field using a regex and than use a stats command to aggregate them.

Only as an example, if you want to take the oracle errors that are always "ORAXXXX" where XXXX is a four digit number, you should use a search like this:

index=your_index
| rex "?(<ora_error>ORA\d+)"
| stats count BY ora_error

To better help you I'd need a sample of your logs.

Ciao.

Giuseppe

0 Karma

pradeepkm
Explorer

This is how my event looks like 

Processing started….

Record No 1
Reason code : :Component code not found 

Record No.3

Reason code: :Address not found 

Record No.7

Reason code::Address not found 

processing ended at…

0 Karma
Get Updates on the Splunk Community!

Advanced Splunk Data Management Strategies

Join us on Wednesday, May 14, 2025, at 11 AM PDT / 2 PM EDT for an exclusive Tech Talk that delves into ...

Uncovering Multi-Account Fraud with Splunk Banking Analytics

Last month, I met with a Senior Fraud Analyst at a nationally recognized bank to discuss their recent success ...

Secure Your Future: A Deep Dive into the Compliance and Security Enhancements for the ...

What has been announced?  In the blog, “Preparing your Splunk Environment for OpensSSL3,”we announced the ...