Splunk Search

Return adjacent entries until a specific string is found?

awendler
Explorer

This is a rather complex question, at least for me, so please bear with me.

In one of our custom logs, when an error is triggered, there will be > 1 lines returned in the log. The exact number cannot be predicted as it will vary based on how bad the error is, and the error message does not indicate how many lines there will be. When the last relevant line is shown, the next log message will be a predictable string.

What I am trying to create is a search that will look for this error message, and return the error message and every line after it until it reaches that second string.

This is an example of the data:

INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ERROR | task-scheduler-6 | |  |2015-06-23 01:40:21 [AbstractRunnerTask]:70  -
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | INSERT_UPDATE CategoryCategoryRelation;target(OBFUSCATED)
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;0500;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;0100;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;0300;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;020;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;0205;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;050;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;0200;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;060;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;030;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ,,,value is NULL for mandatory attribute CategoryCategoryRelation.source;010;
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 |
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ERROR | task-scheduler-6 | |  |2015-06-23 01:40:21 [AbstractRunnerTask]:71  - end of unresolved lines for file ::: 2_merc_hierarchy-en-17642.csv
INFO   | jvm 2    | main    | 2015/06/23 01:40:21.795 | ERROR | task-scheduler-6 | |  |2015-06-23 01:40:21 [AbstractRunnerTask]:72  - error processing the file ::: 2_merc_hierarchy-en-17642.csv

[AbstractRunnerTask]:70 heralds the beginning of the reported errors. The next lines are the specifics of the error. The final line is "error processing the impex file"

Tags (2)
0 Karma
1 Solution

aljohnson_splun
Splunk Employee
Splunk Employee

The quick and easy (and slow in a different sense) way would be to use transaction.

... | transaction startswith="ERROR" endswith="error processing the file"

or something of the sort. I'm sure there's a better way though !

View solution in original post

aljohnson_splun
Splunk Employee
Splunk Employee

The quick and easy (and slow in a different sense) way would be to use transaction.

... | transaction startswith="ERROR" endswith="error processing the file"

or something of the sort. I'm sure there's a better way though !

awendler
Explorer

That is actually perfect, thank you

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!

Automated Threat Analysis: Available in ES Premier

Automated Threat Analysis: Centralize and Accelerate Phishing Investigations in Splunk Enterprise ...

What’s New in Splunk AI: Volume 02

Welcome to the second edition of “What’s New in Splunk AI” where we look at the latest and greatest updates, ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...