Splunk Search

How to use only the latest group of events for each machine to display in the table

nksiba
Engager

Hello dear Community!

I have a set of separate machines logging number of different events to Splunk, each group can be identified by some unique 'RunId' field. Each machine send event multiple times per day.
Via the some simple 'table' query I can display all collected info on the Dashboard, like

```
index=idx1 sourcetype=machines_monitoring

| table RunId, MachineName, Environment, Version, State

```
Now I have a lot of raws displayed for each machine with the different information about the each machine's state. How can I filter the events to have the table showing only the current state of each machine, without duplicates, using only the latest group of events sent by each machine?
I've tried 'latest(RunId) by RunId, MachineName, Environment, Version, State` with no changes, all duplicated values are displayed as usual.

Labels (2)
Tags (1)
0 Karma
1 Solution

livehybrid
SplunkTrust
SplunkTrust

Hi @nksiba 

To display only the current state of each machine without duplicates, you need to filter the events to show only the latest event for each machine. You can achieve this by using the stats command to group the events by MachineName (and any other relevant fields) and then use the latest function to get the most recent event for each group. Here's how you can modify your query:

index=idx1 sourcetype=machines_monitoring
| stats latest(RunId) as RunId, latest(State) as State, latest(Environment) as Environment, latest(Version) as Version by MachineName
| table RunId, MachineName, Environment, Version, State

Please let me know how you get on and consider adding karma to this or any other answer if it has helped.
Regards

Will

View solution in original post

nksiba
Engager

Thanks a lot!

0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @nksiba 

To display only the current state of each machine without duplicates, you need to filter the events to show only the latest event for each machine. You can achieve this by using the stats command to group the events by MachineName (and any other relevant fields) and then use the latest function to get the most recent event for each group. Here's how you can modify your query:

index=idx1 sourcetype=machines_monitoring
| stats latest(RunId) as RunId, latest(State) as State, latest(Environment) as Environment, latest(Version) as Version by MachineName
| table RunId, MachineName, Environment, Version, State

Please let me know how you get on and consider adding karma to this or any other answer if it has helped.
Regards

Will

Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...