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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...