Splunk Search

Need help on why my eval if statement isn't working

mninansplunk
Path Finder

Hello,  I've been researching this online for over a day and nothing seems to be working for me.  I have 2 EVAL IF statements that simply looks at the network.connectType field.  

| eval MOBILE=if(network.connectType="MOBILE","1","0")

| eval WIFI=if(network.connectType="WIFI","1","0")

I am in need of creating a table that would show the count of MOBILE, WIFI, TOTAL, by Branch.

i.e  Branch | Total | WIFI | MOBILE

I'm able to create the table, but the two evals always show the same counts as the Total count.  I can't figure out why I am doing wrong.

The search I am using is the following:

index=main "details.package"="com.siteone.mobilepro", "details.tag"="Connectivity Service", event=NoConnectivityEvent, "details.message.additionalInfo.NetworkAccessStatus"="None"
| fields network.connectType, event, userSettings.site
| eval MOBILE=if(network.connectType="MOBILE","1","0")
| eval WIFI=if(network.connectType="WIFI","1","0")
| stats values("userSettings.site") as Branch, count(event) as "Total Disconnects", count(MOBILE) as "Cellular Disconnects", count(WIFI) as "Wifi Disconnects" by "userSettings.site"
| table Branch, "Total Disconnects", "Wifi Disconnects", "Cellular Disconnects"

 

Any help on this would be awesome and much appreciated.

Thanks

 

 

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

count(MOBILE) and count(WIFI) are merely counting the instances where the field is present (not null). Since you have set them to either 1 or 0, they are always present. Either set them to 1 or null(), or use sum(MOBILE) and sum(WIFI) instead

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

count(MOBILE) and count(WIFI) are merely counting the instances where the field is present (not null). Since you have set them to either 1 or 0, they are always present. Either set them to 1 or null(), or use sum(MOBILE) and sum(WIFI) instead

mninansplunk
Path Finder

Awesome, that did the trick, thank you very much for the quick help!!!

Thanks

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mninansplunk ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @mninansplunk,

sometimes ields with dot insied don't work in eval, so you have two solutions:

use quotes:

| eval MOBILE=if("network.connectType"="MOBILE","1","0")
| eval WIFI=if("network.connectType"="WIFI","1","0")

or use a rename before the eval:

| rename network.connectType AS network_connectType
| eval MOBILE=if(network_connectType="MOBILE","1","0")
| eval WIFI=if(network_connectType="WIFI","1","0")

I prefer the second solution.

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...