Splunk Search

Finding a percentage for every value in another field

stakor
Path Finder

I am looking for source IPs that have a high percentage of being blocked. The evaluations below work fine if I use just one source IP. But I want to test multiple source IPs, and am not sure how to cycle through them. I know that Splunk has a foreach command. I am not sure how to cycle the testing SPL into the 'foreach loop'. (Or how to refer to the src variable for purposes of getting a total count.)

<Network_Search>  (src="1.1.1.1" OR src="1.1.1.2")
| stats count(eval(src="")) as totalCount,count(eval(result="blocked")) as blocked
| eval blockedPercent=blocked/totalCount*100
| where blockedPercent>50
| table src, blockedPercent

Anyone good at nesting this type of search?

I did find:
https://answers.splunk.com/answers/298931/how-to-calculate-percentage-for-each-category.html

But when I use:

<Network_Search>  (src="1.1.1.1" OR src="1.1.1.2")
| eventstats count(src) as total |stats count(eval(result="blocked")) as count by src |eval percent=round(count/total*100,2) 
| table src,percent

I get a blank percentage. Not sure if I should stick with event stats, or try a foreach...

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

<Network_Search>
| stats count AS totalCount count(eval(result="blocked")) AS blockedCount BY src
| eval blockedPercent=round(100*blockedCount/totalCount, 2)
| search blockedPercent>50
| table src, blockedPercent

View solution in original post

woodcock
Esteemed Legend

Like this:

<Network_Search>
| stats count AS totalCount count(eval(result="blocked")) AS blockedCount BY src
| eval blockedPercent=round(100*blockedCount/totalCount, 2)
| search blockedPercent>50
| table src, blockedPercent
Get Updates on the Splunk Community!

Detecting Brute Force Account Takeover Fraud with Splunk

This article is the second in a three-part series exploring advanced fraud detection techniques using Splunk. ...

Buttercup Games: Further Dashboarding Techniques (Part 9)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Buttercup Games: Further Dashboarding Techniques (Part 8)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...