Splunk Search

Parse first/last error in an event

icyfeverr
Path Finder

I have an event that has multiple lines, it can have multiple Errors in the event and I need to query either the first or last error from the event. Does anyone know how to do this by chance? I am needing it for a chart to display errors, but the multiple codes are causing the numbers to be skewed.

Tags (2)
0 Karma

icyfeverr
Path Finder

Correct, it is a multiline event using a regex to parse the Start and End on the indexer manually for a transaction in our system. I have stopped working on this piece due to the random number of errors that can be thrown, as there is no consistency.

0 Karma

dart
Splunk Employee
Splunk Employee

So you could use dedup to find the most recent event:

 sourcetype=foo | dedup error_code by host | timechart count by error_code

Does this give you what you need?

0 Karma

icyfeverr
Path Finder

I have stopped working on this piece due to the random number of errors that can be thrown, as there is no consistency. I appreciate the help, but will need to address at a later time after modifications to the logs can be done.

0 Karma

kristian_kolb
Ultra Champion

And this is an example of a single event, not six events?

... | rex "ERROR\]\s?(?<err_msg>[^\r\n]+)"

ought to work..

0 Karma

icyfeverr
Path Finder

[2010-08-12 11:54:56.281][ERROR] [ 4363 ] - User credentials are invalid.
[2010-08-12 11:54:56.281][ERROR]AuthResultUserUnknownException
[2010-08-12 11:54:56.281][ERROR] [ 4370 ] - User ****** is unknown. Auth result code = 15.
[2010-08-12 11:54:56.281][ERROR]AuthInterfaceException
[2010-08-12 11:54:56.281][ERROR] [ 4363 ] - User credentials are invalid.

0 Karma

lukejadamec
Super Champion

Can you post an example event?
That will make it easier to create a regex that will grab the first or last error in it.

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...