Splunk Search

Fill null delta for multiple object

Julia1231
Communicator

Hello all,

I have a set of data as below. In the column is value of each id according to the time

_timeid = 12345id = 12347id = 12349
01-févr10205
02-févr12459
03-févr155312
04-févr17  
05-févr   
06-févr 120 
07-févr 14056
08-févr5715060
09-févr6015575
10-févr7017590

 

I would like to  calculate delta then fill the null delta.


I have this piece of  code, until here I can calculate the delta for each id, I am finding the solution for the filling null delta:

index="index" [|inputlookup test.csv
| search id=1234**
|timechart latest(value) as valLast span=1d by id
|untable _time id valLast
|streamstats current=false window=1 global=false first(valLast) as p_valLast by id
| eval delta=valLast-p_valLast
| xyseries _time id delta
|streamstats count(eval(if(isnull(delta),0,null()))) as count by id

Result: columns display delta values according to each id in a time

_timeid = 1id = 2id = 3
01-févr   
02-févr2254
03-févr383
04-févr2  
05-févr   
06-févr 120 
07-févr 2056
08-févr57104
09-févr3515
10-févr102015

 

Thanks in advanced!

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am not 100% clear what it is you are trying to achieve but does this help?

ndex="index" [|inputlookup test.csv
| search id=1234**
|timechart latest(value) as valLast span=1d by id
|untable _time id valLast
|streamstats current=false window=1 global=false first(valLast) as p_valLast by id
| eval delta=valLast-p_valLast
| fillnull value=0
| xyseries _time id delta
0 Karma

Julia1231
Communicator

Hi @ITWhisperer ,

Thanks for your feedback and sorry it's not clear.

Here is the original data (base on delta)

Julia1231_0-1652097151512.png

And here is what I aim to do:

Julia1231_1-1652097250566.png

Get the value of 08 feb and divide by the total null bar + 1 (8 feb) and refill to null and 8 feb.

The other id is expected the same way of doing

 

Thanks

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Is valLast always the same or higher than the previous value for each id?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming ascending values and events in time order, try something like this

``` Assuming your search gives events in time order ```
``` fill nulls with -1 (so they can be detected after untable) ```
| fillnull value=-1
``` untable so events can be processed by id ```
| untable _time id valLast
``` split off original null fields ```
| eval null=if(valLast=-1,1,0)
| eval valLast=if(valLast=-1,null(),valLast)
``` filldown using max (assumes valLast doesn't decrease) ```
| streamstats max(valLast) as valLast by id
``` find change in valLast and detect start and end of sequence of nulls ```
| streamstats range(valLast) as diff range(null) as nulls window=2 global=f by id
``` count nulls by id ```
| streamstats sum(null) as nullnumber global=f by id
``` calculate null number at start of sequence ```
| eval start=if(null=1 AND nulls=1,nullnumber,null())
``` calculate null number at end of sequence ```
| eval end=if(null=0 AND nulls=1,nullnumber,null())
``` filldown null number by id ```
| streamstats max(start) as start by id
``` calculate number of events to spread the difference over ```
| eval nullsplusone=end-start+1+1
``` spread the difference across nulls and end of sequence ```
| eval diffspread=diff/nullsplusone
``` reverse events ```
| reverse
``` filldown spread diff by id ```
| streamstats last(diffspread) as lastdiff by id
``` calculate new difference based on whether first non-null after a sequence or originally null ```
| eval newdiff=if(isnotnull(end) OR null=1, lastdiff, diff)
``` reverse to original order ```
| reverse
``` rechart by time and id ```
| xyseries _time id newdiff

Comments to hopefully make it clear what's going on

0 Karma
Get Updates on the Splunk Community!

Demo Day: Strengthen Your SOC with Splunk Enterprise Security 8.1

Today’s threat landscape is more complex than ever. Security operation centers (SOCs) are overwhelmed with ...

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...