Reporting

How can I produce a report showing the host, oldest data, and newest data?

DPWSplunkPOC
Explorer

How can I produce a report showing the host, oldest data, and newest data? I want to expand on what the metadata search can produce. I'd like to narrow down the hosts to a particular sourcetype.

0 Karma

javiergn
Super Champion

What about this?

| tstats min(_time) as oldestData, max(_time) as newestData where index=YOURINDEXNAMEHERE, sourcetype=YOURSOURCETYPEHERE groupby host
| fieldformat oldestData = strftime(oldestData, "%Y-%m-%d %H:%M:%S")
| fieldformat newestData = strftime(newestData, "%Y-%m-%d %H:%M:%S")

bwooden
Splunk Employee
Splunk Employee

Depending on your goals, the metadata command may work

| metadata type=hosts | convert ctime(firstTime) ctime(lastTime) | rename firstTime as oldestData lastTime as newestData | table host *Data

Edited to add: I missed the second part of your question. You may want to additionally leverage the metasearch command: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Metasearch

Off the top of my head, you could join result sets from both metadata and metasearch commands. An example showing first and last timestamp of events from each host having syslog data would look like this:
| metasearch sourcetype=syslog | dedup sourcetype host | join host [| metadata type=hosts] | convert ctime(firstTime) ctime(lastTime) | rename firstTime as oldestData lastTime as newestData | table sourcetype host *Data

0 Karma

DPWSplunkPOC
Explorer

Is there a way to narrow the results of this search to a particular sourcetype?

0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...