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!

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability

Solve Problems Faster with New, Smarter AI and Integrations in Splunk Observability As businesses scale ...