Splunk Search

How to get the field value from a previous event to compare with the value of the same field in the following event?

ludoz13
Path Finder

Hi all,

I'd like to get value on a field to my previous event to compare this same field with the current value

Explanation: I have:

  • 9/25/14 2:05:55.000, PM field1=abc, field2=abc2
  • 9/25/14 2:05:54.000, PM field1=def, field2=def2
  • 9/25/14 2:05:53.000, PM field1=ghi, field2=ghi2

I would like to do

  • 9/25/14 2:05:55.000, PM field1=abc, field2=abc2, old_field2=def2
  • 9/25/14 2:05:54.000, PM field1=def, field2=def2, old_field2=ghi2
  • 9/25/14 2:05:53.000, PM field1=ghi, field2=ghi2, old_field2=

And streamstats last() current=f window=1 global=f, give me this :

  • 9/25/14 2:05:55.000, PM field1=abc, field2=abc2, old_field2=
  • 9/25/14 2:05:54.000, PM field1=def, field2=def2, old_field2=abc2
  • 9/25/14 2:05:53.000, PM field1=ghi, field2=ghi2, old_field2=def2

Would anyone have any idea?

Thanks,

Ludovic

Labels (1)
Tags (2)
0 Karma
1 Solution

Ayn
Legend

streamstats operates on events in the order they come in, which in a historical search is reverse chronological. So last() will carry the value of the last (and therefore earliest) event that streamstats has encountered in the event stream.

I don't know of a good way to have the latest event carry the value for a "previous" event, because to streamstats, that "previous" event doesn't exist at the time when it runs. You could always use reverse for flipping the order of the events, but that's obviously pretty ugly...

View solution in original post

Ayn
Legend

streamstats operates on events in the order they come in, which in a historical search is reverse chronological. So last() will carry the value of the last (and therefore earliest) event that streamstats has encountered in the event stream.

I don't know of a good way to have the latest event carry the value for a "previous" event, because to streamstats, that "previous" event doesn't exist at the time when it runs. You could always use reverse for flipping the order of the events, but that's obviously pretty ugly...

somesoni2
Revered Legend

You can add "|sort 0 _time" before streamstats and "| sort 0 -_time" after streamstats to get what you need.

0 Karma

Ayn
Legend

That would have the same effect as reverse though...

0 Karma

ludoz13
Path Finder

Hello Ayn,

Thank you very much for your response.
I understand better now streamstats command and I understand why It will be diffcult to get value.

I am going to see if there are another way to do what I want.

Thanks again,

Bye,

Ludovic

0 Karma

SasiB137
Engager

how did you fix this issue ?

0 Karma

sirikimeite
Observer

Hello,
Did you have a solution to this issue?

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In January, the Splunk Threat Research Team had one release of new security content via the Splunk ES Content ...

Expert Tips from Splunk Professional Services, Ensuring Compliance, and More New ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Observability Release Update: AI Assistant, AppD + Observability Cloud Integrations & ...

This month’s releases across the Splunk Observability portfolio deliver earlier detection and faster ...