Splunk Search

How to sort results in a search by using a lookup table?

dbturner
New Member

So here is what I want to do. I want to be able to search an index and sort the results via subnet/location contained in a lookup file. I'm am not sure how to do this. I need to be able to sort the results by the ip they return that matches a subnet which is in CIDR in the lookup file and then once the results are in that subnet I will know that location.

I hope that makes sense.

Basic version:
I have an ip list that I do not know who owns what IP. I have a lookup file that contains the subnets in cidr and their locations. I want to sort my results by location based on the IP address in the search using a lookup table.

0 Karma
1 Solution

maciep
Champion

Not sure if i'm missing something, but if you already have the lookup and the subnet column is set for cidr match, then i think you can just use lookup to get the location, then sort the results however you want.

<your base search>
| lookup your_lookup_table ip_field_in_table AS ip_field_in_data OUTPUT location_field_in_table AS location 
| sort 0 location

also, not sure if the location is specific to your organization, but if it's just a general location and the ip's are public, you could also try using the iplocation command

View solution in original post

0 Karma

maciep
Champion

Not sure if i'm missing something, but if you already have the lookup and the subnet column is set for cidr match, then i think you can just use lookup to get the location, then sort the results however you want.

<your base search>
| lookup your_lookup_table ip_field_in_table AS ip_field_in_data OUTPUT location_field_in_table AS location 
| sort 0 location

also, not sure if the location is specific to your organization, but if it's just a general location and the ip's are public, you could also try using the iplocation command

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 ...