Splunk Search

How to display count as zero when no events are returned

493600
Explorer

I have three lookup files and I am trying to find out which one has a zero count.

Below is the query I am using.

 

| inputlookup file_intel
| inputlookup append=true ip_intel
| inputlookup append=true http_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key

I want to know which threat_key has a zero count for threat_key=*risklist_hrly*. I have tried fillnull, its not working.

 

I can only see the one that has count. I want to get the one that has zero count.

493600_0-1716384237230.png

 

 

 

Labels (3)
0 Karma
1 Solution

493600
Explorer

Hello,

 

I have got the solution to this. We need to first create results and initialize the count as 0. it will create one table with 4 rows. Then join that with the other lookup files. Below is the query that I have used:

| makeresults
| eval threat_key="p_default_domain_risklist_hrly"
| eval count=0
| append
[| makeresults
| eval threat_key="p_default_hash_risklist_hrly"
| eval count=0 ]
| append
[| makeresults
| eval threat_key="p_default_ip_risklist_hrly"
| eval count=0]
| append
[| makeresults
| eval threat_key="p_default_url_risklist_hrly"
| eval count=0 ]
| fields - _time
| append
[| inputlookup ip_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key ]
| append
[| inputlookup file_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key
]
| append
[| inputlookup http_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key ]
| stats sum(count) as count by threat_key
| search count=0

 

View solution in original post

0 Karma

493600
Explorer

Hello,

 

I have got the solution to this. We need to first create results and initialize the count as 0. it will create one table with 4 rows. Then join that with the other lookup files. Below is the query that I have used:

| makeresults
| eval threat_key="p_default_domain_risklist_hrly"
| eval count=0
| append
[| makeresults
| eval threat_key="p_default_hash_risklist_hrly"
| eval count=0 ]
| append
[| makeresults
| eval threat_key="p_default_ip_risklist_hrly"
| eval count=0]
| append
[| makeresults
| eval threat_key="p_default_url_risklist_hrly"
| eval count=0 ]
| fields - _time
| append
[| inputlookup ip_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key ]
| append
[| inputlookup file_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key
]
| append
[| inputlookup http_intel
| search threat_key=*risklist_hrly*
| stats count by threat_key ]
| stats sum(count) as count by threat_key
| search count=0

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @493600 ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

493600
Explorer

@gcusello 

Thanks for your response but this doesn't work. Its making all the count 0 when we add | eval count=0

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| inputlookup file_intel
| stats count BY threat_key
| eval lookup=1
| append [ | inputlookup ip_intel | stats count BY threat_key | eval lookup=2 | fields threat_key lookup ]
| append [ | inputlookup http_intel | stats count BY threat_key | eval lookup=4 | fields threat_key lookup ]
| stats sum(lookup) AS mask BY threat_key
| search threat_key=*risklist_hrly*

if mask is 7 the key is in all files

if it is 6 it is in ip_intel and http_intel

if it is 5 it is in file_intel and http_intel

etc.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @493600,

please try this:

| inputlookup file_intel
| stats count BY threat_key
| eval count=0
| append [ | inputlookup ip_intel | eval count=0 | fields threat_key count ]
| append [ | inputlookup http_intel | eval count=0 | fields threat_key count ]
| stats sum(count) AS total BY threat_key
| search threat_key=*risklist_hrly*

if in all lookups there's a field called "threat_key".

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

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

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...