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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...