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!

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