Splunk Search

Identify events based on the incremental change of a value

punichannibal
Explorer

Hi,

I have have a list of events that contain a customer ID. I'm trying to detect when I have a sequence of events with incremental changes to the ID

Example:

- event A - ID0

- event B - ID1

- event C- ID2

- event D - ID3

 

I might have other events between these increments that could have unrelated IDs (i.e: event A ID0 - event H ID 22, event B ID1)

I've tried using | streamstats current=f last(CustomerID) as prev_CustomerID
| eval increment = CustomerID - prev_CustomerID but without any luck.

 

Do you guys know a way this could be achieved ?

 

 

 

 

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming ID is a numeric, your solution should work. You could also try range with window of 2. Here is a runanywhere example demonstrating both techniques

| makeresults format=csv data="event,id
A,1
B,2
C,4
D,5"
| streamstats range(id) as range window=2
| streamstats current=f last(id) as prev_id
| eval increment=id-prev_id

punichannibal
Explorer

Hello, 

Thank you for the answer. Indeed trying a range with a windows of 2 spawns results. However, I'm not picking up on the first start of the sequence (ID 0 and ID 1)  but only the last 4 IDs ( 2/3/4/5)

Any ideas ?

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

What were you expecting for the first id if there is no previous row?

0 Karma

punichannibal
Explorer

I see your logic, my bad. I'm trying to identify the start of the sequence as well even thought there is no increment based on the previous row.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval range=coalesce(range, id)
0 Karma

punichannibal
Explorer

I'm not sure where this goes, can you please explain what it changes?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Perhaps if you provided some more realistic (but anonymised) sample events, and a representation of the output you are trying to achieve, we may be able to help you to a solution.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults format=csv data="event,id
A,1
B,2
C,4
D,5"
| streamstats range(id) as range window=2
| eval range=coalesce(range, id)
Get Updates on the Splunk Community!

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...

Unlock Instant Security Insights from Amazon S3 with Splunk Cloud — Try Federated ...

Availability: Must be on Splunk Cloud Platform version 10.1.2507.x to view the free trial banner. If you are ...