Splunk Search

How to search the distinct counts of failed and successful usernames used in login transactions, group by IP, and total for each IP?

hokieb
New Member

I am trying to pull distinct counts of failed and successful usernames used in login transactions grouped by IP address along with overall totals for each IP.

Example:

.... | stats count(eval(status=="FAILED")) as FAILED, dc(if(status=="FAILED", username)) as FAILED_UNIQUE, count(eval(status=="SUCCESS")) as SUCCESS, dc(if(status=="SUCCESS", username)) as SUCCESS_UNIQUE, count(username) as TOTAL, dc(username) as TOTAL_UNIQUE by ipv4 | sort - TOTAL

My results give me correct values in everything except the dc() columns...I suppose since the filtering is not possible within the dc() function. Are there any other ways to efficiently accomplish this?

0 Karma
1 Solution

bmacias84
Champion

You could try something like this. using eval and if to create new fields and copy existing

....| eval failed=if(status=="FAILED",1,0) 
| eval success=if(status=="SUCCESS",1,0) 
| eval failed_name=if(status=="FAILED",username,isnull())
| eval success_name=if(status=="SUCCESS",username,isnul())
| stats sum(failed) as FAILED, sum(sucess) as SUCCESS, dc(failed_name) as FAILED_UNIQUE, dc(success_name) as SUCCESS_UNIQUE, count(username) as TOTAL_UNIQUE by ipv4
|sore - TOTAL

View solution in original post

0 Karma

bmacias84
Champion

You could try something like this. using eval and if to create new fields and copy existing

....| eval failed=if(status=="FAILED",1,0) 
| eval success=if(status=="SUCCESS",1,0) 
| eval failed_name=if(status=="FAILED",username,isnull())
| eval success_name=if(status=="SUCCESS",username,isnul())
| stats sum(failed) as FAILED, sum(sucess) as SUCCESS, dc(failed_name) as FAILED_UNIQUE, dc(success_name) as SUCCESS_UNIQUE, count(username) as TOTAL_UNIQUE by ipv4
|sore - TOTAL
0 Karma

hokieb
New Member

That got it! Thanks!

Note for others I changed these 2 lines though...
| eval failed_name=if(status=="FAILED",username,NULL)
| eval success_name=if(status=="SUCCESS",username,NULL)

0 Karma
Get Updates on the Splunk Community!

Exporting Splunk Apps

Join us on Monday, October 21 at 11 am PT | 2 pm ET!With the app export functionality, app developers and ...

Cisco Use Cases, ITSI Best Practices, and More New Articles from Splunk Lantern

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

Build Your First SPL2 App!

Watch the recording now!.Do you want to SPL™, too? SPL2, Splunk's next-generation data search and preparation ...