Splunk Search

How to find all results in an inputlookup and display zero if no events are matched?

justinfranks
Path Finder

I have a semi-static CSV that I am using for an input lookup to generate usage data on trial application we have in our environment. The lookup is working well except if no events are matched to the lookup. In these cases, I would like to display a zero count.

Here is my lookup code:

sourcetype=etv e=logon s=139 ur=TEACHER [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid, CurrentTrialStartDate as earliest  | format] | stats dc(u) as dis_count by cname, cid

This gives me a table with two entries:

Caringbah High School                CS04370     1
Hurlstone Agricultural High School   CS04252     17

However, I know that there are 4 entries in my CSV:

| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid, CurrentTrialStartDate as earliest

gives the following output:

CS04252  07/23/2014:00:00:00
CS04370  07/18/2014:00:00:00
CS05096  07/17/2014:00:00:00
CS09634  07/21/2014:00:00:00

Is it possible to display a zero in the dis_count field if no matching events are found?

Tags (2)
0 Karma
1 Solution

HiroshiSatoh
Champion

cid and cname is a one-to-one?

sourcetype=etv e=logon s=139 ur=TEACHER [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid, CurrentTrialStartDate as earliest | format] | stats dc(u) as dis_count by cname, cid|append [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid|eval cname=""|eval dis_count=0|table cname,cid,dis_count]|stats first(cname),sum(dis_count) by cid

View solution in original post

HiroshiSatoh
Champion

cid and cname is a one-to-one?

sourcetype=etv e=logon s=139 ur=TEACHER [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid, CurrentTrialStartDate as earliest | format] | stats dc(u) as dis_count by cname, cid|append [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid|eval cname=""|eval dis_count=0|table cname,cid,dis_count]|stats first(cname),sum(dis_count) by cid

HiroshiSatoh
Champion

Has been changed.

sourcetype=etv e=logon s=139 ur=TEACHER [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid, CurrentTrialStartDate as earliest | format] | stats dc(u) as dis_count by cname, cid|append [| inputlookup etvd_trial_ids_week4.csv | rename "Customer ID" as cid|eval dis_count=0|table cname,cid,dis_count]|stats sum(dis_count) by cname,cid

However, I think [earliest] is not functioning correctly.

0 Karma

justinfranks
Path Finder

I added a lookup to find the name of the school but this worked great. Thanks.

0 Karma

justinfranks
Path Finder

Sorry. cname is a lookup based on the cid field.

0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...