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

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...