Splunk Search

Getting counts on multiple fields, while grouping by one of those fields

AlexBryant
Path Finder

I am working with the fields srcip and malware-type. I need to show how many instances of each type of malware have been observed for each srcip, and then group them by src_ip.

For example:

127.0.0.1: TrojanHorse (2)

Worm (1)

192.168.7.256: TrojanHorse (1)

1.8.9.10: Worm (5)

Rootkit (2)

The code "stats values(malware-type) by srcip" will list the types of malware grouped by srcip, but getting the counts in there (while still grouping by srcip) has me stumped...can anyone help me out? Thanks!

Tags (1)
0 Karma

AlexBryant
Path Finder

Yep, although the parentheses are necessary...just needed the data. Thanks!

0 Karma

Gilberto_Castil
Splunk Employee
Splunk Employee

Are the counts of malware types represented by the digits in the parentheses?

0 Karma

Gilberto_Castil
Splunk Employee
Splunk Employee

To answer this question we should be aligned. We are making a couple of assumptions.

If we use your sample of data, here is how we will see that in Splunk.

alt text

From there we extract the IP,malware type and count (assuming that is embedded in the parentheses).

alt text

The inline extractions to obtain these fields are:

... | rex "(?<srcip>\d+\.\d+\.\d+\.\d+):\s(?<info>.+)" 
    | rex field=info max_match=0 "(?<malware_type>[a-zA-Z]+)\s+\((?<mcount>\d+)\)"



You can combine a number of functions with the stats command. Here is a complete list.
You may want to try:

... | stats list(malware_type) count(malware_type) by srcip

Which will return the following. I don't know that this is what you are looking for but here it is nonetheless.

alt text

More than likely, this may be a more effective way to represent this data:

... | stats list(malware_type) AS malware_type list(mcount) AS mcount sum(mcount) as total by srcip 



alt text

All together:

... | rex "(?<srcip>\d+\.\d+\.\d+\.\d+):\s(?<info>.+)"
    | rex field=info max_match=0 "(?<malware_type>[a-zA-Z]+)\s+\((?<mcount>\d+)\)" 
    | stats list(malware_type) AS malware_type list(mcount) AS mcount sum(mcount) as total by srcip 
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...