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!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...