Splunk Search

Comparing Values Based on Another Field

genesiusj
Builder

Hello,
I'm thinking is real simple, but I have been digging in the weeds for so long I am unable to see this simple answer.

Field Names: File, Method
Field Values: File - A, B, C Method - Success, Fail
Counting the number of events by File/Method combination
Searching for File(s) where the count of Fail is greater than the count of Success.

| stats count(status) AS numEvents BY file, statusMsg
| sort numEvents
| stats list(statusMsg) AS "HTTP Method", list(numEvents) AS "Events by Method", sum(numEvents) AS sumEvents BY file
| rename file AS "File Name", sumEvents AS "Events by File"
| sort -"Events by File"

...

This is a file we don't want in our results.
badNum.doc  
500 Internal Server Error     12
200 Success                  149

This is a file we do want in our results.
UPDATE_NEW.doc                  
200 Success                  116
500 Internal Server Error    475

Thanks and God bless,
Genesius

0 Karma

jpolvino
Builder

Here is one way to do it, using Run Anywhere SPL:

| makeresults
| eval raw="File=A,Method=Fail File=A,Method=Success File=A,Method=Fail File=B,Method=File File=B,Method=Success File=C,Method=Fail File=C,Method=Success File=C,Method=Fail File=A,Method=Success File=A,Method=Success File=B,Method=Fail"
| makemv raw | mvexpand raw | rename raw AS _raw | kv
| table File Method
| stats count AS Vol by File,Method
| xyseries File Method Vol
| where Fail>Success
0 Karma

genesiusj
Builder

@jpolvino
Thanks for the quick response.
My post was very generic/minimal. We have over 70 Files. And the number of methods covers all of the HTTP methods: 200 range, 300 range, 400 range, and 500 range.
Thanks and God bless,
Genesius

0 Karma

jpolvino
Builder

Ok then, you'll have to use a new "status" field. Here is an example where 200 is defined as "Pass" and everything else is "Fail"

| makeresults
| eval raw="File=A,Method=200 File=A,Method=300 File=A,Method=400 File=B,Method=500 File=B,Method=200 File=C,Method=300 File=C,Method=500 File=C,Method=500 File=A,Method=500 File=A,Method=200 File=B,Method=400"
| makemv raw | mvexpand raw | rename raw AS _raw | kv
| table File Method
| eval status=if(Method==200,"Pass","Fail")
| stats count AS Vol by File,status
| xyseries File status Vol
| where Fail>Pass
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!

Splunk Enterprise Security: An Automated Phishing Response Workflow

Originally posted on Splunk.com.   Key takeaways  The volume of phishing emails can overwhelm even the most ...

Sharper ES Detections, Agentic AI Integrations, Smarter Workload Management, and More ...

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

Data Outage Monitoring and Reporting

We’ve all been there, right? Living our best life, working on our Splunk environment, when out of nowhere a ...