Splunk Search

Find values for specific distinct counts

mztopp
Explorer

Hello all!

I was hoping to take a distinct count and show either the count, or if the count is 1, show the value that is being counted. For example, index=random | stats dc(src_port) AS port_count count by src_ip would populate:

src_ip    |      port_count

-----------------------------------------------------

1.2.3.4             6

2.3.4.5             (1) Port 443

3.4.5.6              4

 

Or something to this effect. Thanks!

Labels (3)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

There may be a few ways to do that.  Here's one.

index=random 
| stats values(src_port) AS ports count by src_ip 
| eval port_count = if(mvcount(ports)==1,"(1) Port " . mvindex(ports,0), mvcount(ports))
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

There may be a few ways to do that.  Here's one.

index=random 
| stats values(src_port) AS ports count by src_ip 
| eval port_count = if(mvcount(ports)==1,"(1) Port " . mvindex(ports,0), mvcount(ports))
---
If this reply helps you, Karma would be appreciated.
0 Karma

mztopp
Explorer

Thank you!

0 Karma
Get Updates on the Splunk Community!

Now Available: Cisco Talos Threat Intelligence Integrations for Splunk Security Cloud ...

At .conf24, we shared that we were in the process of integrating Cisco Talos threat intelligence into Splunk ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Easily Improve Agent Saturation with the Splunk Add-on for OpenTelemetry Collector

Agent Saturation What and Whys In application performance monitoring, saturation is defined as the total load ...