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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...