Splunk Search

Problem with case statement using eval

selinakvle
Explorer

Hi all,

Getting this error:

Error in 'eval' command: The expression is malformed. Expected ).

I'm following the following tutorial:

https://www.splunk.com/blog/2017/06/01/enhancing-splunk-visualizations-with-mapbox.html

Everything was going fine until I got to the part of the search where I had to add the eval case statement color parameters. Can someone tell me where I'm going wrong? Thanks!

sourcetype="test" severity="critical" | iplocation src prefix=start_ | iplocation dest prefix=end_ | search start_Country="*" end_Country="*" | table start_lat start_lon end_lat end_lon app | eval animate="yes", pulse_at_start="yes" | eval color = case (
match(app, "ssh"), "#c0392b"
    match(app, "web-browsing"), "#e67e22",
    match(app, "unknown-tcp"), "#f1c40f",
    match(app, "webdav"), "#27ae60",
    1==1, "#7f8c8d")

It doesn't look like I'm missing anything..but then again..Its always better with another set of eyes:)

Tags (2)
0 Karma
1 Solution

martinpu
Communicator

Missing a comma after first match, this should help

sourcetype="test" severity="critical" 
    | iplocation src prefix=start_ 
    | iplocation dest prefix=end_ 
    | search start_Country="*" end_Country="*" 
    | table start_lat start_lon end_lat end_lon app 
    | eval animate="yes", pulse_at_start="yes" 
    | eval color = case (
        match(app, "ssh"), "#c0392b",
        match(app, "web-browsing"), "#e67e22",
        match(app, "unknown-tcp"), "#f1c40f",
        match(app, "webdav"), "#27ae60",
        1==1, "#7f8c8d")

Additionally, one useful thing for formatting your queries, if you press CTRL and \ at the same time while in the search window, your query gets automatically formatted to be readable, try it out, it makes troubleshooting queries a lot easier.

View solution in original post

skoelpin
SplunkTrust
SplunkTrust

You're missing a comma on line 2. Fix that and it will work

0 Karma

selinakvle
Explorer

Thank you...face palm

0 Karma

martinpu
Communicator

Missing a comma after first match, this should help

sourcetype="test" severity="critical" 
    | iplocation src prefix=start_ 
    | iplocation dest prefix=end_ 
    | search start_Country="*" end_Country="*" 
    | table start_lat start_lon end_lat end_lon app 
    | eval animate="yes", pulse_at_start="yes" 
    | eval color = case (
        match(app, "ssh"), "#c0392b",
        match(app, "web-browsing"), "#e67e22",
        match(app, "unknown-tcp"), "#f1c40f",
        match(app, "webdav"), "#27ae60",
        1==1, "#7f8c8d")

Additionally, one useful thing for formatting your queries, if you press CTRL and \ at the same time while in the search window, your query gets automatically formatted to be readable, try it out, it makes troubleshooting queries a lot easier.

selinakvle
Explorer

Thank you, I feel dumb now.

0 Karma

skoelpin
SplunkTrust
SplunkTrust

No need to feel dumb, everyone goes through this and understands the missing parenthesis error message doesn't always mean the parenthesis are missing

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...