Splunk Search

How to edit my search to find the number of continuous days a user did not work if this is not recorded in the logs?

troyward
Explorer

I have Windows Kerberos logs that I have turned into a summary table by day by user. I am trying find the way to determine the number of continuous days when the person doesn't work, but this is kind of hard to do because if they didn't work....there is no record. My initial thought was:

index=summary source=daily_kerberos_summary success=T
| bucket _time span=1d
| stats count by _time username 
| eval worked=if(count!=0,1,0)
| streamstats count by username worked reset_on_change=true

This sort of identifies groupings of them working (although even that isn't actually working really), but doesn't begin to answer when they aren't working. Ideas?

Thanks,

Troy

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try. This should give you times when the username didn't work for at least 1 day. My need some tweak if you want to list the dates when user was absent.

 index=summary source=daily_kerberos_summary success=T
 | bucket _time span=1d
 | stats count by username  _time 
 | streamstats current=f window=1 values(_time) as prev_time by username
 | eval daysNotWorked=((_time-prev_time)/86400) -1
 | where daysNotWorked>0 | eval lastWorkedOn=strftime(prev_time,"%F %T")

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try. This should give you times when the username didn't work for at least 1 day. My need some tweak if you want to list the dates when user was absent.

 index=summary source=daily_kerberos_summary success=T
 | bucket _time span=1d
 | stats count by username  _time 
 | streamstats current=f window=1 values(_time) as prev_time by username
 | eval daysNotWorked=((_time-prev_time)/86400) -1
 | where daysNotWorked>0 | eval lastWorkedOn=strftime(prev_time,"%F %T")
0 Karma

rjthibod
Champion

How about this? This will chart the number of consecutive of days off based on my testing.

 index=summary source=daily_kerberos_summary success=T
 | fields _time username
 | timechart span=1d limit=100 dc(username) by username 
 | untable _time username count 
 | eval off = if(count>0, 0, 1) 
 | table _time username off 
 | sort -username +_time 
 | streamstats current=t global=f reset_after="("off=0")" sum(off) as daysoff by username 
 | eval daysoff = if(off=0, 0, daysoff)
 | timechart span=1d max(daysoff) as daysoff by username
0 Karma
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 ...