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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...