Splunk Search

How to delete events which has timestamp order decreasing?

Kirthika
Path Finder

I have the following table

Timestamp 

2021-08-09 12:26:55.7852
2021-08-09 12:26:56.2278
2021-08-09 12:26:56.2278
2021-08-09 12:26:56.3939
2021-08-09 12:26:39.2861
2021-08-09 12:26:40.3430
2021-08-09 12:26:41.3482
2021-08-09 12:26:41.4832
2021-08-09 12:26:56.8794
2021-08-09 12:26:57.8846
2021-08-09 12:26:58.9398
2021-08-09 12:26:59.9450
2021-08-09 12:26:59.9700
2021-08-09 12:26:59.9700
2021-08-09 12:27:00.8201
2021-08-09 12:27:00.8401
2021-08-09 12:27:01.0352
2022-03-30 10:09:25.6406
2022-03-30 10:09:25.8007
2022-03-30 10:09:26.8109
2022-03-30 10:09:27.5961
2022-03-30 10:09:27.5961

I have extracted timestamp manually using regex instead of default timestamp. I have different device_ids. Each device_id will have logfile.

I have the following macro query, to remove the events which is decreasing(seconds value are decreasing for the same date marked as bold)

index="xxxx" source="*$Device_ID$*xxxx*"
| eval Device_ID=mvindex(split(source,"/"),5)
| rex field=_raw "(?<timestamp>[^|]+)"
| table Device_ID timestamp
| streamstats count as s_no by Device_ID
| sort 0 - s_no
| table Device_ID s_no timestamp
| streamstats current=f last(timestamp) as last_timestamp by Device_ID
| eval last_timestamp_h=last_timestamp, timestamp_h=timestamp
| eval last_timestamp=strptime(last_timestamp,"%Y-%m-%d %H:%M:%S.%4N")
| eval timestamp=strptime(timestamp,"%Y-%m-%d %H:%M:%S.%4N")
| eval diff=timestamp-last_timestamp
| eval ref=if(diff<0,last_timestamp,null)
| filldown ref
| eval ref_diff=timestamp-ref
| fillnull ref_diff value=0
| search ref_diff>=0
| fields Device_ID s_no timestamp_h


But when i try to run for all devices, some values are missing and got messed.

How can i run for each device_id separately and store the result

 

Labels (5)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...