Splunk Search

Counting events based on IP Subnets

tsheets13
Communicator

I need to create a search to count the number of events in each geographic are of our network.

Each geo area will consist of multiple subnets.

Kentucky 10.10.10 10.10.11 10.10.12
Ohio 10.10.10.20 10.10.10.21
Indiana 10.10.30 10.10.31 10.10.32 10.10.10.33.

The report should simply output total by state:

Kentucky 112
Ohio 87
Indiana 212

All events have a full IP address but I've already used REX to assign the first 3 octets to the field SUBNET.

Thanks

Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You could use a lookup table.

Define a lookup file ("subnets.csv") with two columns: subnet and state. Refer to the lookup file in your query.

<your current search> | lookup subnets.csv subnet OUTPUT state | stats count by state
---
If this reply helps you, Karma would be appreciated.

View solution in original post

rmmiller
Contributor

I answered a very similar question not too long ago.
Take a look here: https://answers.splunk.com/answers/801332/how-do-you-match-ip-address-with-ips-with-cidr-not.html#an...

You don't need to do any fancy regex to extract parts of the IP address. Make Splunk do the work with your lookup! 🙂

Hope that helps!
rmmiller

0 Karma

richgalloway
SplunkTrust
SplunkTrust

You could use a lookup table.

Define a lookup file ("subnets.csv") with two columns: subnet and state. Refer to the lookup file in your query.

<your current search> | lookup subnets.csv subnet OUTPUT state | stats count by state
---
If this reply helps you, Karma would be appreciated.

tsheets13
Communicator

So the lookup would contain 2 columns, subnet and state and nothing else correct?

0 Karma

rmmiller
Contributor

Yes, for your application, you need to have 2 columns: subnet and state.

0 Karma

tsheets13
Communicator

Sorry, typo,

Ohio should be 10.10.20 and 10.10.21

0 Karma

wmyersas
Builder

you can edit your question 🙂

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...