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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...