Splunk Search

Can you limit events to the max numerical value of a given field by the unique value of another field?

andrewgbennett3
New Member

I am trying to limit my search results to events that contain the highest numerical value of a given field (vulnerability score) for each unique value of another field (ip address).

As events are created per vulnerability, there are multiple events with the same ip address but varying vulnerability scores. The goal here is to identify individual events for a given ip address / vulnerability score pair, and then populate a table containing other important field values unique to those events.

Sample Events:
IP: 1.2.3.4 Vulnerability Score: 100
IP: 1.2.3.4 Vulnerability Score: 200
IP: 1.2.3.4 Vulnerability Score: 300

IP: 1.2.3.5 Vulnerability Score: 100
IP: 1.2.3.5 Vulnerability Score: 200
IP: 1.2.3.5 Vulnerability Score: 300

I would like to limit my search to the following events:

IP: 1.2.3.5 Vulnerability Score: 300
IP: 1.2.3.4 Vulnerability Score: 300

How would I achieve this result?

0 Karma
1 Solution

elliotproebstel
Champion

I'd use eventstats to apply the max() by IP address.
Here's some documentation about eventstats:
http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Eventstats

So let's say you have a base search that returns those events above, and you have already extracted the fields ip_address and vulnerability_score. Then here's how I'd do it:
base search | eventstats max(vulnerability_score) AS max_score BY ip_address | where vulnerability_score=max_score | fields - max_score

View solution in original post

elliotproebstel
Champion

I'd use eventstats to apply the max() by IP address.
Here's some documentation about eventstats:
http://docs.splunk.com/Documentation/Splunk/7.0.0/SearchReference/Eventstats

So let's say you have a base search that returns those events above, and you have already extracted the fields ip_address and vulnerability_score. Then here's how I'd do it:
base search | eventstats max(vulnerability_score) AS max_score BY ip_address | where vulnerability_score=max_score | fields - max_score

andrewgbennett3
New Member

This worked perfectly for my needs. Thanks for the quick and detailed response!

0 Karma

elliotproebstel
Champion

Glad to help!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...