Splunk Search

How to find the records based on another search but each happened afterwards

shancao
Engager

Hi, I would like to implement some splunk alert to check if there's any special event that happened after a certain event, all the events are grouped by the same request-id,  wonder if you could help on this, thanks

queryA -   index=app  class=ClassA  conditionA=aVal | fields  rid, _ time | table rid, _time,   each result (rid, _time) is unique

queryB -   index=app  class=ClassB conditionB=bVal   rid=queryA.rid and _time > queryA._time

I would like to get the alert if queryB has a result.

 

If it is represented as a SQL, it would be like this 

select  field1, fiedl2 ....  from queryB as B, 
             (select id, _time from queryA where  afield1=someval and afield2=val2) as A
where B.id=A.id and B._time > A._time

Any help would be greatly appreciated, thanks

Labels (2)
0 Karma
1 Solution

VatsalJagani
SplunkTrust
SplunkTrust

You can try something like this:

index=app ((class=ClassA  conditionA=aVal) OR (class=ClassB conditionB=bVal))
| eval time_classA=if((class=ClassA conditionA=aVal), _time, null())
| eval time_classB=if((class=ClassB conditionB=bVal), _time, null())
| stats count, latest(time_classA) as time_classA, latest(time_classB) as time_classB by rid
| where time_classB > time_classA

 

Hope this helps. Kindly accept the solution if it is helpful.

View solution in original post

VatsalJagani
SplunkTrust
SplunkTrust

You can try something like this:

index=app ((class=ClassA  conditionA=aVal) OR (class=ClassB conditionB=bVal))
| eval time_classA=if((class=ClassA conditionA=aVal), _time, null())
| eval time_classB=if((class=ClassB conditionB=bVal), _time, null())
| stats count, latest(time_classA) as time_classA, latest(time_classB) as time_classB by rid
| where time_classB > time_classA

 

Hope this helps. Kindly accept the solution if it is helpful.

Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco + Splunk! We’ve ...