Getting Data In

Difference between latest log time and system time

shakSplunk
Path Finder

Hi all,

I have one field that simply shows that latest timestamp of logs.

i) I was wondering how can I find the difference between the latest log time and the current system time?

ii) Then with that value I was hoping to check run a condition and print the condition to another field (e.g. timeliness). The condition I wanted to implemented was that if the difference is greater than 3 hours, then input "Out of Sync" in the timeliness field. However, in the alternative case, enter "Synced" in the timeliness field. 

My latest log time is in the following format:  2021-07-23 02:54:09

Any help would be greatly appreciated!

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The first step is to convert the latest log time into integer form so it can be compared to the current time.  Use the strptime function for that.

... | eval lastLogEpoch=strptime(lastLogTime, "%Y-%m-%d %H:%M:%S")
| eval status=if(lastLogEpoch > relative_time(now(), "-3h"), "Synced", "Out of Sync")
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The first step is to convert the latest log time into integer form so it can be compared to the current time.  Use the strptime function for that.

... | eval lastLogEpoch=strptime(lastLogTime, "%Y-%m-%d %H:%M:%S")
| eval status=if(lastLogEpoch > relative_time(now(), "-3h"), "Synced", "Out of Sync")
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...