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
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...