Splunk Search

time compare

chaitup
New Member

Hi Guys,
We have a scheduled PowerShell script which will give the output in a log file which will have a status of “LastDirSyncTime” time in UTC time as below on every 15 minutes.

LastDirSyncTime : 08-11-2019 07:35:17

Now our requirement is;
Compare the LastDirSyncTime (which is in UTC) with my Splunk Computer’s current time (Which is in PST) and provide the time difference. Our main goal is to trigger an alert in Splunk when ever “LastDirSyncTime” is more than 30 minutes.
Can some one please provide me a query to extract the time difference in minutes so that we can configure the required alerts.

0 Karma

woodcock
Esteemed Legend

Like this:

index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo"
| stats max(_time) AS _time BY host
| eval age = now() - _time
| where age >= (30 * 60)

This will work fine if you were not lazy and you used the LastDirSyncTime as your event's _time. If you did not, then you will have to do it like this:

index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo"
| stats latest(LastDirSyncTime) AS _time BY host
| eval _time = strptime(_time, "%m-%d-%Y %H:%M:%S")
| eval age = now() - _time
| where age >= (30 * 60)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

To compare timestamps they must first be converted to epoch (integer) form. Then you can subtract them to get the difference in seconds. From there, simple math should get you the desired result.

... | eval eLastDirSyncTime=strptime(LastDirSyncTime, "%d-%m-%Y %H:%M:%S")
| eval diffMin = (now() - eLastDirSyncTime) / 60
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

App Platform's 2025 Year in Review: A Year of Innovation, Growth, and Community

As we step into 2026, it’s the perfect moment to reflect on what an extraordinary year 2025 was for the Splunk ...

Operationalizing Entity Risk Score with Enterprise Security 8.3+

Overview Enterprise Security 8.3 introduces a powerful new feature called “Entity Risk Scoring” (ERS) for ...

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...