Splunk Search

Creating a table that shows the number of times a variable is a given value

hcastell
Path Finder

Newbie to Splunk and trying to resolve the following issue. Here's my search string:

index=ipdirectindex 
|eval DOCSNRRdy=case(RxSNR=="n/a", "1", RxSNR >="30", "0", RxSNR <"30", "1") 
| eval DOCTxPWRRdy=case(TxPwr=="n/a", "1", TxPwr < "57", "0", TxPwr >"57", "1") 
| eval DOCRxPWRRdy=case(RxPwr=="n/a", "1", RxPwr >= "-15" OR RxPwr <="15", "0", RxPwr <"-15" OR RxPwr >"15", "1") 
|eval Success=case(Success=="TRUE", "0", Success=="FALSE", "1") 
|eval foo=DOCSNRRdy+DOCTxPWRRdy+DOCRxPWRRdy+Success

Basically what it does is check that the variables DOCSNRRdy,DOCTxPWRRdy and DOCRxPWRRdy fall within an acceptable range where they would be considered as passed or failed if outside the range:

|eval DOCSNRRdy=case(RxSNR=="n/a", "1", RxSNR >="30", "0", RxSNR <"30", "1") 
| eval DOCTxPWRRdy=case(TxPwr=="n/a", "1", TxPwr < "57", "0", TxPwr >"57", "1") 
| eval DOCRxPWRRdy=case(RxPwr=="n/a", "1", RxPwr >= "-15" OR RxPwr <="15", "0", RxPwr <"-15" OR RxPwr >"15", "1") 
|eval Success=case(Success=="TRUE", "0", Success=="FALSE", "1") 
|eval foo=DOCSNRRdy+DOCTxPWRRdy+DOCRxPWRRdy+Success

This part of the search string works fine.

I then sum the values of the four variables in:

|eval foo=DOCSNRRdy+DOCTxPWRRdy+DOCRxPWRRdy+Success

This also works fine and produces a table that shows the sum of the variables for each device that is being tested. What I need now is to be able to produce another table that shows how many times foo is 1, 2 or >2. Tried a few different things but so far none produce the result I'm after. Hope this makes sense. I am pretty new to Splunk so I'm sure there may be more efficient ways to accomplish my task. Just haven't figured them out yet :-). Appreciate your help.

Tags (2)
1 Solution

lguinn2
Legend

Try this:

index=ipdirectindex 
| eval DOCSNRRdy=case(RxSNR=="n/a", "1", RxSNR >="30", "0", RxSNR <"30", "1") 
| eval DOCTxPWRRdy=case(TxPwr=="n/a", "1", TxPwr < "57", "0", TxPwr >"57", "1") 
| eval DOCRxPWRRdy=case(RxPwr=="n/a", "1", 
                        RxPwr >= "-15" OR RxPwr <="15", "0", 
                        RxPwr <"-15" OR RxPwr >"15", "1") 
| eval Success=case(Success=="TRUE", "0", Success=="FALSE", "1") 
| eval foo=DOCSNRRdy+DOCTxPWRRdy+DOCRxPWRRdy+Success
| eval fooCategory=case(foo==1,"1", foo==2,"2",foo>2,">2")
| stats count by fooCategory

I just added the two lines at the end...

BTW, using SHIFT-Enter will let you break your search string into easy-to-read lines. You should be able to cut-and-paste my answer exactly as it appears above.

View solution in original post

lguinn2
Legend

Try this:

index=ipdirectindex 
| eval DOCSNRRdy=case(RxSNR=="n/a", "1", RxSNR >="30", "0", RxSNR <"30", "1") 
| eval DOCTxPWRRdy=case(TxPwr=="n/a", "1", TxPwr < "57", "0", TxPwr >"57", "1") 
| eval DOCRxPWRRdy=case(RxPwr=="n/a", "1", 
                        RxPwr >= "-15" OR RxPwr <="15", "0", 
                        RxPwr <"-15" OR RxPwr >"15", "1") 
| eval Success=case(Success=="TRUE", "0", Success=="FALSE", "1") 
| eval foo=DOCSNRRdy+DOCTxPWRRdy+DOCRxPWRRdy+Success
| eval fooCategory=case(foo==1,"1", foo==2,"2",foo>2,">2")
| stats count by fooCategory

I just added the two lines at the end...

BTW, using SHIFT-Enter will let you break your search string into easy-to-read lines. You should be able to cut-and-paste my answer exactly as it appears above.

hcastell
Path Finder

Thank you very much for your help. It works just fine. Now I can stop hitting my head against the wall :-). I also appreciate your suggestion on using Shift-Enter. That does make things a lot easier to read

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...