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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...