Splunk Search

Why am I getting "Error in '| metadata' " when trying to get the earliest event in a particular index?

_smp_
Builder

I am attempting to determine the earliest event in a particular index by executing the following search over All Time (as instructed by the Metadata command). I am running Splunk Enterprise 7.0.2:
| metadata type=hosts index=vpn

Error in 'metadata': No 'host' key found in results. Cannot merge metadata.

If I choose different time periods, some of them work (previous 30 days, Year to Date) but some do not (previous year). Anyone see this before?

0 Karma

deepashri_123
Motivator

@scottprigge,
You can refer this accepted answer and modify as per your requirement:
https://answers.splunk.com/answers/406967/how-to-use-the-metadata-command-to-search-for-host.html

0 Karma

_smp_
Builder

Interestingly enough, this search also fails with the same error I mentioned above:
| metadata type=hosts index=vpn | eval age=now()-firstTime | where age<604800

0 Karma

niketn
Legend

@scottprigge, can you try the tstats command and see how it behaves:

| tstats count earliest(_time) as EarliestTime latest(_time) as LatestTime where index="vpn" by host
| fieldformat EarliestTime=strftime(EarliestTime,"%Y-%m-%d %H:%M:%S") 
| fieldformat LatestTime=strftime(LatestTime,"%Y-%m-%d %H:%M:%S")
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

_smp_
Builder

That seems to work. Not sure I would have thought to use tstats. Any idea why metadata doesn't work?

0 Karma
Get Updates on the Splunk Community!

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...