Splunk Search

How to pass multiple fields in Case or IF commands

devsru
Explorer

Hi Everyone,

I have some events with the field Private_MBytes and host = vmt/vmu/vmd/vmp

I want to create a case when host is either vmt/vmu/vmd and Private_MBytes  > 20000 OR when host is vmp and  Private_MBytes > 40000 then it should display the events with severity_id 4. Example

eval severity_id=if(Private_MBytes >= "20000" AND host IN [vmd*,vmt*,vmu*],4,2)

eval severity_id=if(Private_MBytes >= "40000" AND host ==vmp*,4,2)

 

Note :  if Private_MBytes > 40000, and then if there is any vmd/vmu/vmt it should display severity_id 4 only and for vmp also.

Labels (4)
Tags (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

If I must guess, the use of wildcard characters make your search not returning your desired results? (Syntax-wise, I am not sure if IN operator can use square brackets.)  As you only illustrated two values, no need to use case.

| eval severity_id=if(Private_MBytes >= 20000 AND searchmatch("host IN (vmd*,vmt*,vmu*)") OR Private_MBytes >= 40000 AND host LIKE "vmp%", 4, 2)

 

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @devsru ,

you have to correlate your conditions using the boolean operators AND and OR and the parenthesys, aligned with the logic you need:

| eval severity_id=if((Private_MBytes>=20000 AND host IN ("vmd*","vmt*","vmu*")) OR (Private_MBytes>=40000 AND host="vmp*"), 4, 2)

Ciao.

Giuseppe

0 Karma

yuanliu
SplunkTrust
SplunkTrust

If I must guess, the use of wildcard characters make your search not returning your desired results? (Syntax-wise, I am not sure if IN operator can use square brackets.)  As you only illustrated two values, no need to use case.

| eval severity_id=if(Private_MBytes >= 20000 AND searchmatch("host IN (vmd*,vmt*,vmu*)") OR Private_MBytes >= 40000 AND host LIKE "vmp%", 4, 2)

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @devsru ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Customers Increasingly Choose Splunk for Observability

For the second year in a row, Splunk was recognized as a Leader in the 2024 Gartner® Magic Quadrant™ for ...