Splunk Search

Table with count and latest date

giuces
Engager

Hi all,

i need to create a table that count for every product how many events are accepted or rejected.

In addition to this fields the latest event date should be shown with the count. Table should be like this

ProductLatest AcceptedTotal AcceptedLatest RejectedTotal Rejected
Bike10/11/20213512/11/202114
Skate11/11/20219913/11/20215

 

the first part of the query is pretty easy:

...| stats count(eval(action="accepted)) AS "Total Accepted" count(eval(action="rejected)) AS "Total rejected" by product | rename product AS Product

I'm not able to retrieve the latest date for every  kind of action, tried with latest(_time) without success.

Many thanks

 

Labels (1)
0 Karma

aasabatini
Motivator

Hi @giuces 

try the stats function like this:

stats latest(eval(if(action="rejected", _time, NULL()))) AS "Latest Rejected"

 

Ale 

“The answer is out there, Neo, and it’s looking for you, and it will find you if you want it to.”
0 Karma

giuces
Engager

thanks aasabatini,

i'm little be confused where do i have to insert portion of search yo suggest in the old one

 

...| stats count(eval(action="accepted)) AS "Total Accepted" count(eval(action="rejected)) AS "Total rejected" by product | rename product AS Product | table Product "Total Accepted" "Total Rejected" ?

 

Regards

0 Karma

aasabatini
Motivator

Hi @giuces 

 

try like this

 stats count(eval(action="accepted)) AS "Total Accepted" count(eval(action="rejected)) AS "Total rejected" latest(eval(if(action="rejected", _time, NULL()))) AS "Latest Rejected" by product | rename product AS Product
“The answer is out there, Neo, and it’s looking for you, and it will find you if you want it to.”
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...