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!

New Year, New Changes for Splunk Certifications

As we embrace a new year, we’re making a small but important update to the Splunk Certification ...

Stay Connected: Your Guide to January Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

[Puzzles] Solve, Learn, Repeat: Reprocessing XML into Fixed-Length Events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...