Im currently having trouble with query to get result of user activity duration after office hour within a month. i expected result will be like below: Query A: user A = 13d 22h 12m 2s user B = 10d 15h 27m 3s OR Query B: user A=320h 23m 2s user B=267h 42m 1s Both answer can be acceptable for me to get as i try multiple set of query for the result above. Both query take time range after 5.30pm until 8.00am only for a month. Below sample query : Query A: | eval date_hourmin = strftime(_time, "%H%M") | where date_hourmin>=1730 OR date_hourmin<=800 | transaction user,date_hourmin | stats sum(duration) as duration by user | sort - duration | eval string_dur = tostring(round(duration), "duration") | eval formatted_dur = replace(string_dur,"(?:(\d+)\+)?0?(\d+):0?(\d+):0?(\d+)","\1d \2h \3m \4s") | eval result=replace(formatted_dur, "^d (0h (0m )?)?","") | table user duration string_dur formatted_dur result Query B: | eval date_hourmin = strftime(_time, "%H%M") | where date_hourmin>=1730 OR date_hourmin<=800 | convert timeformat="%b %Y" ctime(_time) as date_month | streamstats earliest(date_hourmin) as time_in latest(date_hourmin) as time_out by date_month | eval duration=time_out-time_in | stats values(src_ip) as SourceIP values(srcPort) as SourcePort values(dstService) as DestService earliest(time_in) as TimeIn latest(time_out) as TimeOut values(dest_ip) as DestIP values(dstPort) as DestPort sum(duration) as TotalDuration count by date_month,user | eval secs=TotalDuration%60,mins=floor((TotalDuration/60)%60),hrs=floor((TotalDuration/3600)%60) | eval HOURS=if(len(hrs)=1,"0".tostring(hrs), tostring(hrs)),MINUTES=if(len(mins)=1,"0".tostring(mins), tostring(mins)),SECONDS=if(len(secs)=1,"0".tostring(secs), tostring(secs)) | eval Time=HOURS.":".MINUTES.":".SECONDS | table user SourceIP SourcePort DestIP DestPort DestService Time count | sort - duration limit=10 Both query display the result, HOWEVER, its look like both query are not giving accurate result. Ive been struggling for this kind of query for a month now, perhaps im missing something here. Really appreciated if anyone can help n assist on this. TQ.
... View more