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

 

Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...