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
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 ...