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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...

Level Up Your Workflow: Mastering Splunk Cloud Management via Terraform

Tech Talk Recap   From Chaos to Control: Scaling Splunk Cloud with Infrastructure as Code Managing apps in ...