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!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...