Splunk Search

How to compare when a field value changes from current to previous?

Glasses
Builder

I am looking to find events where IP address changes from previous to current, however using fist(ip) and last(ip) misses the events in between the first and last...

Ideally I am looking to find when a change occurs for the IP value and then look at the previous IP value... this comparison is then used to find ip geoloc and calc the speed = dist/time with haversine app.

Thank you

0 Karma
1 Solution

DalJeanis
Legend

Look at the streamstats command for this. Any tracking of change over time, streamstats is your go-to verb.

We'll assume there is a key called user.

your search that gets the records you want, with at least these fields  
| fields _time user someIP
| sort 0 _time 
| streamstats current=f last(someIP) as priorIP last(_time) as priorTime  by user
| where NOT (someIP=priorIP)
 ... the remainder of your search. 

View solution in original post

DalJeanis
Legend

Look at the streamstats command for this. Any tracking of change over time, streamstats is your go-to verb.

We'll assume there is a key called user.

your search that gets the records you want, with at least these fields  
| fields _time user someIP
| sort 0 _time 
| streamstats current=f last(someIP) as priorIP last(_time) as priorTime  by user
| where NOT (someIP=priorIP)
 ... the remainder of your search. 

Glasses
Builder

Wow that is awesome!!! Thanks

DalJeanis
Legend

You are quite welcome. streamstats processes the records in order, remembering only the records it has already seen, so you must sort the records in the order you want before you apply the command.

0 Karma

Glasses
Builder

so that is the purpose of sort 0 > return all results, thanks

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...