Splunk Search

Finding the hosts who time difference is 1hr to 10hrs ?

kteng2024
Path Finder

Hi,

i want to print the hosts,Time difference whose lastTime and recentTime is between 1hr to 10hrs . Below is the query i came up with, but it is not working. Can some one please help me with this ?

| metadata index=xyz type=hosts | eval difference = if((lastTime – recentTime) >=1 OR <= 10, hosts,”no hosts” | table hosts,difference

Thanks

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

lastTime and recentTime are epoch timestamps with second resolution, comparing with 1 and 10 is looking for between 1 and 10 seconds. Using OR would always yield true, any number is "greater than one or less than ten". Additionally, the part after the OR has nothing to compare the ten with.

Try this:

| metadata ... | eval hours = (lastTime - recentTime)/3600 | where hours >=1 AND hours <= 10 | table host hours

Note, you likely want (recentTime - lastTime) instead of (lastTime - recentTime), unless your environment is weird.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

One is "A minus B", the other is "B minus A" - the difference between the two will be whether you get positive or negative values.

It depends on what you're looking for - hosts with old data arriving now, or hosts with future data arriving now.

0 Karma

kteng2024
Path Finder

can i please know the difference between (recentTime - lastTime) & (lastTime - recentTime) because when data is streaming both the field values are equal.

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