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
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...