Splunk Search

How to fetch the time of the latest event?

zacksoft
Contributor

My log contain some events that we call 'bonus_events'. And 'bonus_events' happen once or twice a week.
I want to subtract the the current time from the time when the latest bonus_event happened.

For this I want to fetch the time of the latest event.

This is what I have written,

host="lak1200.ramana.com" source="/apps/games/prizes-*" bonus
| eval sub = now() - x

x indicates the time of the latest event of base_query result.

Tags (1)
0 Karma
1 Solution

adonio
Ultra Champion

hello there,

the field _time represents the timestamp on the event
try this:

   host="lak1200.ramana.com" source="/apps/games/prizes-*" bonus
    | eval sub = now() - _time

this will give you the gap in seconds between your event/s and the moment the search was executed

hope it helps

View solution in original post

0 Karma

adonio
Ultra Champion

hello there,

the field _time represents the timestamp on the event
try this:

   host="lak1200.ramana.com" source="/apps/games/prizes-*" bonus
    | eval sub = now() - _time

this will give you the gap in seconds between your event/s and the moment the search was executed

hope it helps

0 Karma

FrankVl
Ultra Champion

And to apply this only to the latest event, simply insert a | head 1 in between those 2 lines.

zacksoft
Contributor

@FrankVl Thank you. The I head 1 did the trick.

0 Karma

adonio
Ultra Champion
host="lak1200.ramana.com" source="/apps/games/prizes-*" bonus
| head 1
| eval sub = now() - _time

if it solves it, please mark the question as answered and up vote any helpful comments

zacksoft
Contributor

Just to be clear, _time indicates the time of the latest event that my base query produces, right?
My base query produces around 20 events in a month time frame and I would like the time of the latest event only.

Thank you.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...