Splunk Search

compare the number of events from 2 subsearches in different indexes

imrago
Contributor

I would like to create an alert if the number on events is different in two subsearches.

subsearch1 = "index=index1 | dedup checksum | stats count"

subsearch2 = "index=index2 | dedup checksum | stats count"

unsuccessful attempts: 1) using subsearch

index=index1 | dedup checksum | stats count | search count > [search index=index2 | dedup checksum |stats count | search count]

2) using set diff

set diff [search index=index1 | dedup checksum] [search index=index2 | dedup checksum]
Tags (2)
1 Solution

gkanapathy
Splunk Employee
Splunk Employee
index=index1 OR index=index2 | dedup index,checksum | stats count by index | eval nevents="nevents" | xyseries index nevents count | where index1!=index2

Update:

Actually now that I think about it, this may be clearer and more generally useful:

index=index1 OR index=index2 | dedup index,checksum | stats count(eval(index=="index1")) as index1count, count(eval(index=="index2")) as index2count | where index1count!=index2count

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee
index=index1 OR index=index2 | dedup index,checksum | stats count by index | eval nevents="nevents" | xyseries index nevents count | where index1!=index2

Update:

Actually now that I think about it, this may be clearer and more generally useful:

index=index1 OR index=index2 | dedup index,checksum | stats count(eval(index=="index1")) as index1count, count(eval(index=="index2")) as index2count | where index1count!=index2count
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...