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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...