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!

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud  In today’s fast-paced digital ...

Observability protocols to know about

Observability protocols define the specifications or formats for collecting, encoding, transporting, and ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...