Splunk Search

How to use tstats to show the last event and event time from 30 hosts (in lookup)?

kiran331
Builder

How to use tstats to show the last event and event time from 30 hosts (in lookup)? If I can't use tstats, is there any other way to do this? Any suggestions.

Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

The tstats works on the indexed/metadata fields and _raw is not one of them so you would be able to get the last events timestamp and other metadata information using tstats but not the actual event. If that's OK, then try like this

| tstats max(_time) as latestTime WHERE index=* [| inputlookup yourHostLookup.csv | table host ] by host | convert ctime(latestTime)

If you want the last raw event as well, try this slower method.

index=*  [| inputlookup yourHostLookup.csv | table host ] | dedup host

View solution in original post

somesoni2
Revered Legend

The tstats works on the indexed/metadata fields and _raw is not one of them so you would be able to get the last events timestamp and other metadata information using tstats but not the actual event. If that's OK, then try like this

| tstats max(_time) as latestTime WHERE index=* [| inputlookup yourHostLookup.csv | table host ] by host | convert ctime(latestTime)

If you want the last raw event as well, try this slower method.

index=*  [| inputlookup yourHostLookup.csv | table host ] | dedup host
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...