Splunk Search

Adding the most recent _indextime/_time to results table

lbrhyne
Path Finder

We are attempting to write a report querying multiple indexes, which creates a table using data from each. Our challenge is... When we add indextime or _time the report shows all the indextime for each system in the date range selected. Instead, we want to show only the latest indextime/_time in the report only for each system.

(index=* sourcetype=ActiveDirectory objectCategory="CN=Computer,CN=Schema,CN=Configuration,DC=foo,DC=com") OR (index=windows DisplayName="BitLocker Drive Encryption Service" source="kiwi syslog server")

| eval indextime=strftime(_indextime,"%Y-%m-%d %H:%M:%S")

| eval cn=coalesce(cn,host) | stats values(*) AS * BY cn | search cn=* host=*
       NOT [inputlookup All_Virtual_Machines.csv | rename Name as cn]
| where StartMode!="" AND operatingSystem!="" AND Started!="true"
| rename cn as System, operatingSystem as OS 
| dedup System 

| table System StartMode State Started OS indextime | sort System
0 Karma
1 Solution

cmerriman
Super Champion

It's because you're doing a values(*) in your stats command, which is bringing in every index time. If any of the other fields end up having more than one value, it'll also do the same thing for those.

try doing - using max(_indextime) in the stats command and moving the strftime to the bottom.

(index=* sourcetype=ActiveDirectory objectCategory="CN=Computer,CN=Schema,CN=Configuration,DC=g1net,DC=com") OR (index=windows DisplayName="BitLocker Drive Encryption Service" source="kiwi syslog server")
 | eval cn=coalesce(cn,host) | stats values(*) AS * max(_indextime) as indextime BY cn | search cn=* host=*
        NOT [inputlookup All_Virtual_Machines.csv | rename Name as cn]
 | where StartMode!="" AND operatingSystem!="" AND Started!="true"
 | rename cn as System, operatingSystem as OS 
 | dedup System 
 | table System StartMode State Started OS indextime | eval indextime=strftime(indextime,"%Y-%m-%d %H:%M:%S")| sort System

View solution in original post

cmerriman
Super Champion

It's because you're doing a values(*) in your stats command, which is bringing in every index time. If any of the other fields end up having more than one value, it'll also do the same thing for those.

try doing - using max(_indextime) in the stats command and moving the strftime to the bottom.

(index=* sourcetype=ActiveDirectory objectCategory="CN=Computer,CN=Schema,CN=Configuration,DC=g1net,DC=com") OR (index=windows DisplayName="BitLocker Drive Encryption Service" source="kiwi syslog server")
 | eval cn=coalesce(cn,host) | stats values(*) AS * max(_indextime) as indextime BY cn | search cn=* host=*
        NOT [inputlookup All_Virtual_Machines.csv | rename Name as cn]
 | where StartMode!="" AND operatingSystem!="" AND Started!="true"
 | rename cn as System, operatingSystem as OS 
 | dedup System 
 | table System StartMode State Started OS indextime | eval indextime=strftime(indextime,"%Y-%m-%d %H:%M:%S")| sort System

lbrhyne
Path Finder

Thank you cmerriman! That worked perfectly! I simply copied and pasted your revisions and it worked!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...