Splunk Search

After obtaining the Time difference of two time/date fields, if the time greater than a hr create a alert.

dcephas
Engager

Im pretty new to splunk, so my approach may be incorrect. However, At this time my query is as below:

search query
| eval pollingTime=strptime(requestDate,"%Y-%m-%d %H:%M:%S.%3N") 
| eval drainingTime=strptime(receivedDate,"%Y-%m-%d %H:%M:%S.%3N")
| eval timeDiff=tostring((drainingTime-pollingTime),"duration")
| table requestDate receivedDate timeDiff

Which above Im able to obtain timeDiff value in the format (00:00:0.000000). If I want check wether the value us greater then a hour how should I go about doing this?

My thoughts were something like:

| eval isDelayed=if(timeDiff >= ? )

0 Karma
1 Solution

zacharychristen
Path Finder

You can perform the evaluation before converting the variable to a string. For example:

     ...
    | eval pollingTime=strptime(requestDate,"%Y-%m-%d %H:%M:%S.%3N") 
    | eval drainingTime=strptime(receivedDate,"%Y-%m-%d %H:%M:%S.%3N")
    | eval timeDiff=(drainingTime-pollingTime)
    | where timeDiff>3600 
    | eval timeDiff=tostring(timeDiff, "duration")
    | table requestDate receivedDate timeDiff

If timeDiff is greater than 3600 seconds (1 hour), then only those events will show up.

View solution in original post

zacharychristen
Path Finder

You can perform the evaluation before converting the variable to a string. For example:

     ...
    | eval pollingTime=strptime(requestDate,"%Y-%m-%d %H:%M:%S.%3N") 
    | eval drainingTime=strptime(receivedDate,"%Y-%m-%d %H:%M:%S.%3N")
    | eval timeDiff=(drainingTime-pollingTime)
    | where timeDiff>3600 
    | eval timeDiff=tostring(timeDiff, "duration")
    | table requestDate receivedDate timeDiff

If timeDiff is greater than 3600 seconds (1 hour), then only those events will show up.

dcephas
Engager

Thank you this works perfectly for me

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...