Splunk Search

How to search records sequentially?

disillusioned
New Member

I have a search: index=lab-testresults sourcetype=lab-testresults type=testCase
and inside of the testCase I have a field called success, that tells me if the test passed or failed.
What I want to do is count the number of failures backwards from the most recent record until a record states that the testcase passed. (this is to get how many days in a row the test has failed).

Note: The test can be run multiple times a day, if it has failed all the times in a day that is 1 day failed. But if it has passed at least once, then it returns the number of days failed. If that makes sense.

How can I count the results in order to give me a number of days failed since the last time the test passed

0 Karma

woodcock
Esteemed Legend

Like this:

index="lab-testresults" AND sourcetype="lab-testresults" AND type="testCase"
| reverse
| streamstats count(eval(success="SomeYesValueHere")) AS successID BY host and or other fields here
| stats min(_time) AS _time count AS failures BY successID host and or other fields here
| eval count = count - 1
0 Karma

gfreitas
Builder

Hi,
I believe you can use the command transaction to achieve that.
Using transaction you need to define the boundaries of an event (with startswith and endswith) and it will give you both the number of events in each transaction and how much time between the event start and the end of the event.
More information on that command can be found here: https://docs.splunk.com/Documentation/Splunk/8.0.1/SearchReference/Transaction

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