Splunk Search

0 counts

av3rag3
Engager

Hello,

with this query :

index=abc
| search source = "xyz"
| stats count by source

I can see the count of sources having count more than 0. 
But I cant manage to get the ones with 0 count. 
Anyone able to help me please ? 

Thank you 

Labels (1)
0 Karma

antoniolamonica
SplunkTrust
SplunkTrust

To concur with the above answers, you would have to utilize a lookup file that lists out all of the sources you want to monitor.

Natively, Splunk does not have a source = 0 events. (it doesn't know what it doesn't know).

In the environment we work in, we apply a siar approach but its based on host and whether the sources are coming in or not for our customers.

| tstats values(source) as source, values(sourcetype) as sourcetype
WHERE index=[index]

     [ | inputlookup [myHostLookup].csv
       | fields host ]

by host

| stats count, values(sourcetype) as sourcetype, values(source) as source
by host

| eval Reporting=if(isnull(source), "No Matching Sources", "Yes")
| table host, Reporting, source, sourcetype

---
If this reply helps you, Karma would be appreciated.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @av3rag3 ,

at first, don't use the search command after the main search because you'll have slower searches: put all the search terms as left as possible, possibly in the main search.

Then, why do you use the source as BY clausein stats command, if you always have only one source?

In general, without the condition source="xyz", it's normal that you haven't the results of source=0 because you don't have them from the search.

If you have a list of the sources to monitor, you could insert them in a lookup and add them to the search with count=0, something like this:

index=abc
| stats count by source
| append [ | inputlookup my_source_lookup.csv | eval count=0 | fields source count ]
| stats sum(count) AS total BY source

Ciao.

Giuseppe

bowesmana
SplunkTrust
SplunkTrust

I would suggest a slightly optimal version that does not use the subsearch

index=abc
| stats count by source
| inputlookup append=t my_source_lookup.csv 
| fillnull count
| stats sum(count) AS total BY source

 

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...