Splunk Search

how to display raw result if no specific result is available?

jalfrey
Communicator

I'm doing a pretty basic search which looks for a "connection closed" message and displays a variable called app. I have an automatic lookup which converts the app value to an application name. Not all of the values can be looked up in my lookup table. How do I run a search and display the application name (app_name) and if that's not available then display the app (numeric value)?

Here is the search I have made that calculates bytes sent/received and displays bot the app name and the app numeric value.

app=* "Connection Closed" | stats sum(sent) sum(rcvd) by dst_ip app | lookup sonicwall_app_id app_id as app OUTPUT app_name as Application | fields dst_ip, Application, app, sum(sent), sum(rcvd) | rename dst_ip as "Destination IP" | rename app to "App ID" | rename sum(sent) as "Bytes Sent" | rename sum(rcvd) as "Bytes Received"

Tags (2)
0 Karma
1 Solution

Ayn
Legend

Create a field that uses either the app_name if it's not null, otherwise use app_id:

... | eval yournewfield = coalesce(app_name, app_id) | ...

View solution in original post

Ayn
Legend

Create a field that uses either the app_name if it's not null, otherwise use app_id:

... | eval yournewfield = coalesce(app_name, app_id) | ...

Rob
Splunk Employee
Splunk Employee

+1 on a nice use of coalesce!

0 Karma

jalfrey
Communicator

my final search looks like:

index=sonicwall app=* "Connection Closed" | stats sum(sent) sum(rcvd) by dst_ip app | lookup sonicwall_app_id app_id as app OUTPUT app_name | eval "Application" = coalesce(app_name, app) | fields dst_ip, "Application", sum(sent), sum(rcvd) | rename dst_ip as "Destination" | rename sum(sent) as "Sent Bytes" | rename sum(rcvd) as "Received Bytes"

0 Karma

jalfrey
Communicator

that worked great! Thanks.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...