Splunk Search

How to filter a result with two timestamp ?

mah
Builder

Hi,

I have a search which I want to optimise by replace the join command : 

index="AAA" sourcetype=BBB
| stats count(OK) as OK as TOTAL by Date ID
| bin Date span=1d
| stats sum(OK)  by Date ID
| sort -Date

it returns results like this : 
DateIDOK
2020-09-30XXX123
2020-09-30YYY26
2020-09-29ZZZ763
2020-09-29XXX453

 

I want to retrieve only the last Date of each day but the only way to do that is by catching the last ID which is based on another timestamp. So I have a second request which retrieve the last ID : 

index="AAA" sourcetype=BBB

| stats max(Timestamp) as Timestamp by ID
| sort  Timestamp desc
| head 1

The result is : 

ID
XXX

I use a join command but I would like to know ik there is another way to create the search without the join.

Do you have a better solution ?

Thanks 

 

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

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(ID) as latestID
| where ID=latestID
| fields - latestID
| sort -Date

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(Date) as latestDate by ID
| where Date=latestDate
| fields - latestDate
| sort -Date
0 Karma

mah
Builder

Hi, it does not work because :

- in the first query the timestamp is a field call "Date"

- in the second query the timestamp to get the last ID is "Timestamp" : the query must return just one ID 

Your search still returns events with not always the last ID : 

DateIDOK
2020-09-01XXX (latest)344
2020-09-30AAA867
2020-09-30XXX (latest)3473
2020-09-30BBB5387
2020-09-29BBB

772

2020-09-29XXX (latest)82

 

But what I want is a table like that :

DateIDOK
2020-09-01XXX (latest)344
2020-09-30XXX (latest)3473
2020-09-29XXX (latest)82
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index="AAA" sourcetype=BBB
| bin Date span=1d
| stats sum(OK) by Date ID
| eventstats latest(ID) as latestID
| where ID=latestID
| fields - latestID
| sort -Date

mah
Builder

Great ! It is exactly my need !

Thank you ! 

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

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

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...