Splunk Search

Why does the case statement works until an AND is added to it?

azvargas
Loves-to-Learn

When I have this case statement like this, it "works". It runs and puts values in the iSeries column, but they are wrong.

| eval Platform=case((source="A" OR source="B" OR source="C") , "iSeries", true(),"Other")

When I add an AND to it so that it fulfills the true condition, no values are put in the iSeries column, and everything goes to Other.

| eval Platform=case((source="A" OR source="B" OR source="C") AND (dest=X OR dest=Y OR dest=Z), "iSeries", true(),"Other")

What am I doing wrong?

Labels (1)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

Is your dest X or "X"?

| makeresults
| eval source="A", dest="X"
| eval Platform=case((source="A" OR source="B" OR source="C") AND (dest="X" OR dest="Y" OR dest="Z"), "iSeries", true(),"Other")

 

to4kawa
Ultra Champion

In eval statement,

dest=x means the field dest equals the field x.
As @isoutamo says, you need quotes.

0 Karma

azvargas
Loves-to-Learn

I've tried with and without quotes, and it still doesnt work.

0 Karma

to4kawa
Ultra Champion

>It runs and puts values in the iSeries column.

your working query puts "iSeries" text on Platform field(column).

>it still doesnt work.
what's your expected result?


0 Karma

azvargas
Loves-to-Learn

Correct, my query puts "iSeries" text in the Platform field.  But it only works without the AND clause, but this is not the right condition.  I need it to work with the AND clause portion.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Can you print dest and X etc. if those are fields and not values?

0 Karma

azvargas
Loves-to-Learn

Can you print dest and X etc. if those are fields and not values?

Not sure how to do this.  Its a long query.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

e.g.

| makeresults
| eval foo="A", bar=foo
| eval foobar= "'" . foo . "' '" . bar . "'"
| table foo bar foobar
0 Karma

azvargas
Loves-to-Learn

I'd like to add that I have had this same criteria for close to a year in a dashboard just not in a case statement and it works.  

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 ...