Splunk Search

How to alert when difference in count of two query is greater than some value

icenitesh
Engager

I have a below query where i search two text field and see how many time each occurred and find the difference. 

("SSO Initiated" OR "SSO Completed") | stats count(eval(searchmatch("SSO Initiated"))) as SSO_Initiated count(eval(searchmatch("SSO Completed"))) as SSO_Completed | eval Difference=SSO_Initiated-SSO_Completed

I want to create alert if Difference > 20, then mail needs to be sent.  This check should keep happening every 15 minute and check in last 15 minute if Difference > 20, then trigger mail.

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You already have most of what you need.  Adjust it a little as shown:

index=always_specify_an_index ("SSO Initiated" OR "SSO Completed") earliest=-15m
| stats count(eval(searchmatch("SSO Initiated"))) as SSO_Initiated count(eval(searchmatch("SSO Completed"))) as SSO_Completed 
| eval Difference=SSO_Initiated-SSO_Completed
| where Difference > 20

Save this search as an alert and have the alert trigger when the number of results is not zero.  Set the alert action to Send Email.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You already have most of what you need.  Adjust it a little as shown:

index=always_specify_an_index ("SSO Initiated" OR "SSO Completed") earliest=-15m
| stats count(eval(searchmatch("SSO Initiated"))) as SSO_Initiated count(eval(searchmatch("SSO Completed"))) as SSO_Completed 
| eval Difference=SSO_Initiated-SSO_Completed
| where Difference > 20

Save this search as an alert and have the alert trigger when the number of results is not zero.  Set the alert action to Send Email.

---
If this reply helps you, Karma would be appreciated.
0 Karma

icenitesh
Engager

and how do we check if the Difference is 60% of the SSO Initiated?

0 Karma

richgalloway
SplunkTrust
SplunkTrust
... | eval Threshold = SSO_Initiated * 100/60
| where Difference > Threshold
---
If this reply helps you, Karma would be appreciated.
0 Karma

icenitesh
Engager

Thanks a lot for the reply. One final help.. Can we place 2 where clause in the query ?

 

Like if difference is > 60% and SSO_Initiated > 100 .

Because even if the failure is 1, it becomes 100% failure. so want to have minimum count as 100 before difference is calculated. 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Yes, you can do that.  RTM.

... | eval Threshold = SSO_Initiated * 100/60
| where (Difference > Threshold AND SSO_Initiated > 100)
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...