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!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

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 ...