Splunk Search

How to write the regex to extract the error code from my sample log?

swapnilkale
New Member

How can I find all the error codes from the logs and show it as interesting field?
e.g. Message : Information with Insured. (PL200XXX)
Here PLXXXXX is the error code within the parentheses. What regex or search criteria should I use to make this work? I am new to Splunk and exploring it.

Thanks a lot for your help.
Swap

0 Karma

edrivera3
Builder

Try:
If the error code always starts with PL and there are other values between ( ) in your data.
.. | rex "\((?<err_code>PL\w+)\)"

Good Luck!

alacercogitatus
SplunkTrust
SplunkTrust

This one is pretty simple.

sourcetype=yoursourcetype | rex field=_raw "\((?<errorcode>[^)]+)\)"

This should give you the results you want in errorcode. This is a very quick regex - if you are going to make it "production ready", don't use rex, use the props/transforms to pull it automatically.

swapnilkale
New Member

Thanks a lot guys! I will surely try it today.

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

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