Splunk Search

How to return 0 count of events from a lookup file?

Hithere
Engager

I'm trying to match all domains from a lookup file with a base search and get a count of the events for each one even if there are no events matching (0 count):

mysite.com  count 12
anothersite.com count 5
myothersite.com count 0

 

 

 

 

index=application sourcetype=mysource
| lookup myfile.csv Domain as <corelated event field>
| append [ | inputlookup myfile.csv | fields Domain]
| stats count as total by Domain
| fillnull value=0 total
| table total
| sort -total

 

 

 

 

If you can, please explain your answer - whether there is a syntax error, a keyword misuse, or conceptual error on my part. 

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Hithere,

I was confused with another question, my answer is to have the domains with no logs.

If you want all the domains with status, you could use something like this:

index=application WAFRuleMessage="Anomaly Exceeded" 
| eval Domain=lower(domain)
| stats count as ct_Domain by Domain
| append [ | inputlookup mylookupfile.csv | eval Domain=lower(domain), ct_Domain=0 | fields Domain AGS ENV ct_Domain ]
| stats sum(ct_Domain) as total by AGS ENV Domain
| sort AGS -ENV -count
| eval status=if(total=0,"Not present","Present")
| table AGS ENV Domain status

Ciao.

Giuseppe

 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @Hithere,

please try something like this:

index=application WAFRuleMessage="Anomaly Exceeded" 
| eval Domain=lower(domain)
| stats count as ct_Domain by Domain
| append [ | inputlookup mylookupfile.csv | eval Domain=lower(domain), ct_Domain=0 | fields Domain AGS ENV ct_Domain ]
| stats sum(ct_Domain) as total by AGS ENV Domain
| sort AGS -ENV -count
| where total=0

Ciao.

Giuseppe

Hithere
Engager

This query retrieves all the lookup domains as desired, but all the total count of events for each domain is 0 which is not expected.

Hithere_0-1647276243185.png

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Hithere,

I was confused with another question, my answer is to have the domains with no logs.

If you want all the domains with status, you could use something like this:

index=application WAFRuleMessage="Anomaly Exceeded" 
| eval Domain=lower(domain)
| stats count as ct_Domain by Domain
| append [ | inputlookup mylookupfile.csv | eval Domain=lower(domain), ct_Domain=0 | fields Domain AGS ENV ct_Domain ]
| stats sum(ct_Domain) as total by AGS ENV Domain
| sort AGS -ENV -count
| eval status=if(total=0,"Not present","Present")
| table AGS ENV Domain status

Ciao.

Giuseppe

 

Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...