Splunk Search

Can you help me with my stats count?

jip31
Motivator

hello

I use the request below, which works:

index="windows" sourcetype="wineventlog:Application" "SourceName=*" Type="Critique" OR Type="Avertissement"
| dedup _time SourceName 
| table  _time SourceName |
 stats count by SourceName 
| rename SourceName as Application count as Erreurs 
| sort - Erreurs limit=10

I try to do the count also by host
so i do this :

index="windows" sourcetype="wineventlog:Application" "SourceName=*" Type="Critique" OR Type="Avertissement"
| dedup _time SourceName 
| table  _time SourceName |
 stats count by SourceName host
| rename SourceName as Application count as Erreurs 
| sort - Erreurs limit=10

but it doesn't work.

could you help me?

0 Karma
1 Solution

somesoni2
Revered Legend

The reason second search doesn't work because your table command (line 3) restricts the fields in result to _time and SourceName only. There is not host field after that table command, thus next stats doesn't work.

You can try something like this

index="windows" sourcetype="wineventlog:Application" "SourceName=*" Type="Critique" OR Type="Avertissement"
| stats dc(_time) as Erreurs by SourceName host
| rename SourceName as Application
 | sort - Erreurs limit=10

View solution in original post

0 Karma

jip31
Motivator

many thanks for all your perfect answer

0 Karma

KailA
Contributor

Hey,

You can also use the top function like that :

index="windows" sourcetype="wineventlog:Application" "SourceName=*" Type="Critique" OR Type="Avertissement"
| top 10 SourceName,host

That should return you the same result than the =search you were writing.

KailA

0 Karma

somesoni2
Revered Legend

The reason second search doesn't work because your table command (line 3) restricts the fields in result to _time and SourceName only. There is not host field after that table command, thus next stats doesn't work.

You can try something like this

index="windows" sourcetype="wineventlog:Application" "SourceName=*" Type="Critique" OR Type="Avertissement"
| stats dc(_time) as Erreurs by SourceName host
| rename SourceName as Application
 | sort - Erreurs limit=10
0 Karma

osakachan
Communicator

Hello @jip31,

First of all, you do not need to do dedup if you will do a stats count, you will have the same result and stats count is faster.
Table is only aesthetic, so you do not need to do it at first, or maybe use fields, to have a faster query, but I think it will not be necessary.
And, ah! You had a typo with the field Source name!

Try this query:
index="windows" sourcetype="wineventlog:Application" SourceName=* Type="Critique" OR Type="Avertissement"
| stats count by SourceName host
| rename SourceName as Application count as Erreurs
| sort - Erreurs limit=10

0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

  Ready to master Kubernetes and cloud monitoring like the pros?Join Splunk’s Growth Engineering team for an ...

Wrapping Up Cybersecurity Awareness Month

October might be wrapping up, but for Splunk Education, cybersecurity awareness never goes out of season. ...

🌟 From Audit Chaos to Clarity: Welcoming Audit Trail v2

🗣 You Spoke, We Listened  Audit Trail v2 wasn’t written in isolation—it was shaped by your voices.  In ...