Splunk Search

How to have multiple conditions for each searchmatch case?

herachini
Observer

Hello,

I am currently trying to figure out how to combine the below three searches with different conditions into one query/alert. 

if abc reminder is <1 then trigger an alert

if xyz reminder is <5 then trigger an alert

if 123 reminder is <22 then trigger an alert

Here is my query so far:

index="xyz" sourcetype=xyz
("abc reminder") OR ("xyz reminder") OR ("123 reminder")

earliest=-24h

| eval JobName=case(
searchmatch("abc reminder"), "ABC reminder",

searchmatch("xyz reminder"), "XYZ reminder",

searchmatch("123 reminder"), "123 reminder")

| stats count as ABCJobCount by JobName

| where ABCJobCount<1

| stats count as XYZJobCount by JobName

| where XYZJobCount<1

| stats count as 123JobCount by JobName

| where 123JobCount<1
|eval NetcoolTitle = JobName + " did not complete in last 24 hours"

Labels (4)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

You have a desire to "combine" three conditions (which is very vague), and you have a query.  So, where is the question?  How can others help if we don't know whether that query gives you what you need?  If the query does not meet your requirement, what is the requirement?

Just to point out: Your query suggests three conditions in AND relationship, whereas the opening statements seem to suggest an OR relationship.  Another problem with the illustrated code is that after performing where ABCJobCount<1, the second | count by JobName is not necessarily XYZJobCount as your code seems to assume.

If the three conditions are in OR relationship, simply do

index="xyz" sourcetype=xyz
("abc reminder" OR "xyz reminder" OR "123 reminder")
earliest=-24h
| eval JobName=case(
searchmatch("abc reminder"), "ABC reminder",
searchmatch("xyz reminder"), "XYZ reminder",
searchmatch("123 reminder"), "123 reminder")
| stats count by JobName
| where JobName == "ABC reminder" AND count < 1
 OR JobName == "XYZ reminder" AND count < 5
 OR JobName == "123 reminder" AND count < 22

Hope this helps.

 

0 Karma
Get Updates on the Splunk Community!

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Community Content Calendar, October Edition

Welcome to the October edition of our Community Spotlight! The Splunk Community is a treasure trove of ...