Splunk Search

Unable to do simple calculation of aggregate durations between 2 states by host

smahoney
Path Finder

Given that per host there are 2 events logged, one indicating transition to active and one indicating transition to inactive.  I cant figure out a query that can accurately do this per host given the following stipulations.

Given the first event within the query time range, it can be assumed the host was in the opposite state prior.

Only calculate transitions between the 2 states, if there are multiple same events within transitions, calculate of the time of the first occuring.

Include the latest condition up until the time the search is run.




Labels (4)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

"simple" is a subjective term!

Assuming you can evaluate state based on the events as being either 0 or 1 (I have used a random number to simulate different events), then you could try something like this

| eval state=if(random()%5 == 0, 0, 1)
| streamstats range(state) as changed count as host_event by host global=f window=2
| eval changed = if(host_event == 1, 1, changed)
| where changed == 1
| streamstats range(_time) as interval last(state) as state by host global=f window=2
| appendpipe
    [| stats last(state) as state last(_time) as last_event by host
    | addinfo
    | eval _time=info_max_time
    | eval interval=_time-last_event
    | fields - info_* last_event]
0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...

Updated Data Management and AWS GDI Inventory in Splunk Observability

We’re making some changes to Data Management and Infrastructure Inventory for AWS. The Data Management page, ...