Splunk Search

conditional field choice

wsw70
Communicator

Hello,

I have log files which have both IP numbers (field IP) and corresponding names (field DNSNAME).
I would like to chart (a distribution for instance) based on the names but unfortunately some of them are not available (the value of the field DNSNAME="N/A"). In that case I need to fallback to the IP.

If I always had names I would do

... | stats count by DNSNAME

Is there a way to construct something along the lines of

... | stats count [ if DNSNAME != "N/A" then "by DNSNAME" else "by IP" ) ]

I was looking around the eval & co. functions but the "if" mentioned there seems to work on a given field only (while I want to modify the search itself based on conditions)

Thanks!

Tags (1)
1 Solution

imrago
Contributor

... | eval newfield=if(DNSNAME=="N/A",IP,DNSNAME) | stats count by newfield

View solution in original post

imrago
Contributor

... | eval newfield=if(DNSNAME=="N/A",IP,DNSNAME) | stats count by newfield

wsw70
Communicator

Aahhh - I was looking at the "if" (as I mentioned) but somehow it did not ring a bell.
Thanks!

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