index=live_index source="rest:" state=*
| table _time hostname state
| sort 0 hostname _time
| rename COMMENT as "The above extracts and sorts your current state report records for your requested time period."
| rename COMMENT as "This determines initial state and when the state changes."
| streamstats current=f last(state) as priorstate by hostname
| eval newstate=if(isnull(priorstate) OR priorstate!=state,1,0)
| streamstats sum(newstate) as stateno by hostname
| rename COMMENT as "This rolls together all the consecutive records for a given state."
| rename COMMENT as "and checks to see if we had any hiccups."
| stats min(_time) as _time, max(_time) as max_time, first(state) as state, count as duration by hostname stateno
| eval duration = duration*300
| eval time_span=300+max_time-_time
| eval countflag=case(time_span>duration,"Records missing",time_span<duration,"Records duplicated", true(),null())
| eval duration=if(duration<time_span,time_span,duration)
| eval end_time=_time+duration
| table _time end_time duration hostname state stateno countflag
| rename COMMENT as "We can put out a file for investigating issues with our data "
| appendpipe [ | where isnotnull(countflag) | outputcsv myproblems.csv | where false()]
| rename COMMENT as "Now we can do stats directly on the records and various types of analysis"
| stats count as statecount avg(duration) as avgduration by hostname state
... View more