Splunk Search

Why Stats count command is counting events that are missing in other searches?

abhijeetallu
Engager

The first search query returns a count of 26 for domain X :

index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency") | stats count by domain

 

But when I run the below query to just see the events corresponding to domain=X, I get zero events:

 index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency") domain="X"

 

Any clue why this might be happening

Labels (1)
Tags (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

That generally means X is not X, i.e. if you put 

index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency") domain="*X*"

do you get results

If you do this in your first search

index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency")
| eval trimmed_domain=trim(domain)
| eval bounded_domain=":".domain.":"
| stats count by domain trimmed_domain bounded_domain
| eval trimmed_equal_domain=if(trimmed_domain=domain, "YES", "NO")

you may see whether you have leading or trailing spaces around X and if trimmed_equal_domain is NO, then there are leading/trailing spaces.

The bounded domain makes it easier to see what's what by adding : before and after

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

That generally means X is not X, i.e. if you put 

index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency") domain="*X*"

do you get results

If you do this in your first search

index="web" sourcetype="weblogic_stdout" loglevel IN ("Emergency")
| eval trimmed_domain=trim(domain)
| eval bounded_domain=":".domain.":"
| stats count by domain trimmed_domain bounded_domain
| eval trimmed_equal_domain=if(trimmed_domain=domain, "YES", "NO")

you may see whether you have leading or trailing spaces around X and if trimmed_equal_domain is NO, then there are leading/trailing spaces.

The bounded domain makes it easier to see what's what by adding : before and after

0 Karma

abhijeetallu
Engager

Thank you so much ! it worked. I was clueless what was happening and all this time it was a trailing space character !

0 Karma
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!

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...