Splunk Search

Tally field by value and source and divide by total source count

reigerourich
Engager

Hello, all.

I'm looking for the best method to tally a particular field by value and source and then run division with that tally.

index=abc sourcetype=csv
| eval failpass=if(a!=b,0,1)
| stats count by source, failpass | sort source

Given the above, I'd like to total the failpass=0 by source and the failpass=1 by source, then run division on the total failpass by source.

So if source abc.csv has 20 total events and 13 of those are failpass=0; and 7 of them are failpass=1, and def.csv has 10 events with failpass=0 and 10 events with failpass=1, then I'd show

Source 0 1 div1 div2
abc.csv 13 7 .65 .35
def.csv 10 10 .50 .50

I'm curious if there's a good way to pull that off.

TIA,
Reiger

Tags (1)
0 Karma
1 Solution

renjith_nair
Legend

@reigerourich ,

Try and test against your data

index=abc sourcetype=csv
| eval failpass=if(a!=b,0,1)
| stats count(eval(failpass==0)) as fail,count(eval(failpass==1)) as pass, count as total by source
| eval div1=fail/total, div2=pass/total
| fields - total
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

renjith_nair
Legend

@reigerourich ,

Try and test against your data

index=abc sourcetype=csv
| eval failpass=if(a!=b,0,1)
| stats count(eval(failpass==0)) as fail,count(eval(failpass==1)) as pass, count as total by source
| eval div1=fail/total, div2=pass/total
| fields - total
---
What goes around comes around. If it helps, hit it with Karma 🙂

reigerourich
Engager

Thank you, Renjith, that worked perfectly as written!

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...