Splunk Search

Case with Tag's

hartfoml
Motivator

I am trying to use Case to rename taged events like this

tag=audit OR tag=cleared "" | eval Event=case( tag == audit, "Logging Stoped", tag == cleared, "Logs Cleared" )

The case statement is not working not finding any events and the Event field is not generated.

Tags (2)
0 Karma

Ayn
Legend

Without the quotes, you're asking eval to compare the value of the field tag to the value of the field audit and cleared, respectively. I'm guessing you'd want quotes around those?

0 Karma

hartfoml
Motivator

Thanks Ayn

That make sense, about the quotes I mean. So I tried this;

tag=audit OR tag=cleared ""

This search generated events with;
tag::eventtype, value=audit
tag::eventtype, value=cleared

but when I do this;

tag=audit OR tag=cleared "" | stats count by tag

I get zero results. I guess I am confused about tag relationships.

0 Karma

Ayn
Legend

The quotes are only supposed to be around the VALUE, not the field name as well. So tag == "audit". Otherwise you're just giving case a string and don't tell it what to actually do with it.

0 Karma

hartfoml
Motivator

Oh Sorry i misunderstood the question.

WhenI do this

tag=audit OR tag=cleared "" | eval Event=case( "tag == audit", "Logging Stoped", "tag == cleared", "Logs Cleared" )

I get this error

Error in 'eval' command: The arguments to the 'case' function are invalid

0 Karma

Ayn
Legend

Yes, you're using it without quotes. That is wrong. You just said you got a syntax error with quotes. What was it?

0 Karma

hartfoml
Motivator

I do not get any errors the search runs as expected and generates events as expected but the eval command does not generate the field named "Event" using the case function.

0 Karma

Ayn
Legend

Yup. So what does it look like in your case? What error are you getting?

0 Karma

hartfoml
Motivator

I tried with the added quotes and the case function throws a syntax error.

The example on Splunk docs is like this;
... | eval description=case(error == 404, "Not found", error == 500, "Internal Server Error", error == 200, "OK")

0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...