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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...