Getting Data In

How to use the metadata command to search for hosts that have recently started sending data to Splunk?

jbullough
Path Finder

I'm trying to use the metadata command to find hosts that have recently started sending logs. Basically when firstTime is more recent than 7 days. This is the search I have...

| metadata type=hosts index=* | eval firstday=strftime(firstTime,"%Y-%m-%d") | where firstday>=relative_time(now(),"-7d")

I have tried many variations of this, to no avail. The 'firstday' field shows accurately, but the results are not filtered. Is there something I don't understand about this metadata command? I appreciate the help!

0 Karma
1 Solution

the_wolverine
Champion

Calculate the age of the firstTime
Evaluate against 7d value
7 days = 604800 seconds

| metadata type=hosts index=_internal | eval age=now()-firstTime | where age<604800

View solution in original post

the_wolverine
Champion

Calculate the age of the firstTime
Evaluate against 7d value
7 days = 604800 seconds

| metadata type=hosts index=_internal | eval age=now()-firstTime | where age<604800

jbullough
Path Finder

Actually this gave what appears to be more accurate results. I'll have to see why the other answer isn't giving exactly accurate results. Thanks!

0 Karma

javiergn
SplunkTrust
SplunkTrust

firstTime is epoch
firstday is string
relative_time is epoch

Simply do it this way:

 | metadata type=hosts index=* | where firstTime >= relative_time(now(),"-7d")

jbullough
Path Finder

Wow, I was afraid it was something simple. This worked perfectly, thanks!!

0 Karma

jbullough
Path Finder

This looked right, but after trying the answer below the results are different, and it looks like it's producing more accurate results. I'll dig into why.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...