Splunk Search

Add a new field that evaluates to online or batch

dilbert99
New Member

if I have a string field called batchname that can have any value or not be present e.g.

2012-11-14 10:55:06.000 message=a ; customer=customer1 batchname=batch1

2012-11-14 10:55:07.000 message=b ; customer=customer1

I want to do some stats based the following pseudo code
if batchname is null then type is online
if batchname is not null then type is batch

the nearest I got was fillnull value=online batchname

perhaps I can use eval?
eval type=? | stats count by customer, message, type

Thanks
David

Tags (2)
0 Karma

okrabbe_splunk
Splunk Employee
Splunk Employee

You are on the right path. I would use eval and the isnull() function.

 index=blah |  eval batchname=if(isnull(batchname), "online", "batch")  
 | stats count by customer, message, batchname
0 Karma

sdaniels
Splunk Employee
Splunk Employee

I think you are looking for this:

<your search> | eval type = if(isnull(batchname), "online", "batch") | ...

okrabbe_splunk
Splunk Employee
Splunk Employee

Shane! That is what I get for not refreshing the page 🙂

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...