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!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...