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!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...