Splunk Search

Counting how many days users logged into the server for the last 12 months

splunktrainingu
Communicator

Hello,

 

I am trying to count how many days out of the last 12 months our users logged into two of our servers.  And in the end I want it to display the days out of the 12 months the users logged in. SO if a user logged in 4 time in one day it should count it as 1 day.  

I have tried the "timechart span=1d count by Account_Name"    this looked promising but timechart groups Account_names in OTHER field that is misleading because there are other accounts in that field.

 

index=windows source="WinEventLog:Security" EventCode=4624 host IN (Server1, Server2) Logon_Type IN (10, 7)

| eval Account_Name = mvindex(Account_Name,1)
| timechart span=1d count by Account_Name
| untable _time Account_Name count

 

Labels (3)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

And in the end I want it to display the days out of the 12 months the users logged in. SO if a user logged in 4 time in one day it should count it as 1 day.  

If you are aggregating number of days over 12 months, why do you use timechart?  That splits output into individual days the user logged on, therefore the count is the number of times the user logged on each day, i.e., 4 times.

This is the aggregate

index=windows source="WinEventLog:Security" EventCode=4624 host IN (Server1, Server2) Logon_Type IN (10, 7)
| bucket _time span=1d@d
| eval Account_Name = mvindex(Account_Name,1)
| stats dc(_time) as count  by Account_Name

View solution in original post

Tags (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

And in the end I want it to display the days out of the 12 months the users logged in. SO if a user logged in 4 time in one day it should count it as 1 day.  

If you are aggregating number of days over 12 months, why do you use timechart?  That splits output into individual days the user logged on, therefore the count is the number of times the user logged on each day, i.e., 4 times.

This is the aggregate

index=windows source="WinEventLog:Security" EventCode=4624 host IN (Server1, Server2) Logon_Type IN (10, 7)
| bucket _time span=1d@d
| eval Account_Name = mvindex(Account_Name,1)
| stats dc(_time) as count  by Account_Name
Tags (1)
0 Karma

splunktrainingu
Communicator

What does the "1d@d" for span mean?

0 Karma

yuanliu
SplunkTrust
SplunkTrust

What does the "1d@d" for span mean?

I'm just speculating that you want to count calendar days, not arbitrary 24-hour periods from the time of your search.  If not, lose that @d. (The "@" notation is called "snap-to".  See Specify a snap to time unit.)

splunktrainingu
Communicator

Thank you for explaining this. I didn't know about this syntax.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=windows source="WinEventLog:Security" EventCode=4624 host IN (Server1, Server2) Logon_Type IN (10, 7)

| eval Account_Name = mvindex(Account_Name,1)
| timechart span=1d count by Account_Name useother=f limit=0
| untable _time Account_Name count
0 Karma

splunktrainingu
Communicator

I am sorry this didn't work for me and I tried to get it to work. But I already have a solution.

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...