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!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...