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!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

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