Splunk Enterprise

How to extract ErrorCode from log messages using regex?

dezmadi
Path Finder

I have  messages like below in logs, I want to extract ErrorCode from Those messages, Here ErrorCode is CIS-46031

However there could be space right after ErrorCode or after ErrorCode:

 msg: ErrorCode:CIS-46031,ErrorMessage:Some unknown error occurred in outage daemon request. Please check.,Error occurred in CIS domain events outage processing.

msg: ErrorCode : CIS-46032,ErrorMessage:Some unknown error occurred in outage daemon request. 

msg: ErrorCode :CIS-46033, ErrorMessage:Some unknown error occurred in outage daemon request. 

How can we do the same in Splunk

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| rex "ErrorCode\s*:\s*(?<errorcode>[^,]+),"

View solution in original post

0 Karma

dezmadi
Path Finder

Thanks, but I am still getting it as NULL, I have pasted it below

dezmadi_0-1649060561504.png

Below is the message (Here there is a space between ErrorCode: and  CIS-53030)

  msg: ErrorCode: CIS-53030 Events cannot be processed 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If ErrorCode: doesn't exist in your events, you will get NULL. Are you expecting all events to have ErrorCode in? If so, can you share some of the events which are not matching the rex?

| rex "ErrorCode\s*:\s*(?<errorcode>[^\s,]+),"
| where isnull(errorcode)
0 Karma

dezmadi
Path Finder

ErrorCode exist in the event, however if there is space, it's returning as null in visualisation, For instance, in below event, we have ErrorCode: CIS-53030 (Here there is space between ErrorCode: and CIS-53030), it's showing as NULL

 

  msg: ErrorCode: CIS-53030 Events cannot be processed as WFM is not provisioned for WFM ID

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try it without the tail anchor ","

| rex "ErrorCode\s*:\s*(?<errorcode>[^\s,]+)"
0 Karma

dezmadi
Path Finder

Thanks a lot, it worked

0 Karma

dezmadi
Path Finder

Thanks @ITWhisperer  , It worked

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "ErrorCode\s*:\s*(?<errorcode>[^,]+),"
0 Karma

dezmadi
Path Finder

Thanks, it worked, however in visulalization, it prints as NULL if there's a space in between

For instance it prints NULL for ErrorCode:   CIS-53030

However if it's ErrorCode: CIS-53031, it prints correct value as ErrorCode: CIS-53031

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "ErrorCode\s*:\s*(?<errorcode>[^\s,]+),"
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!

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

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