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
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!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...