Splunk Search

group certain URLs

gerard11
Engager

I have a search that returns events with many different URLs

 

 

index=test URL=*

 

 

I want to obtain a count of events per URL

However some of the URLs are slightly different so I want to group them together

Example of my URL values

/login/
/login/
/api/customer/5542-a44/data
/api/customer/5c77-59w/data
/api/customer/7a88-134/data
/weather/forecast/
/api/savedseach/7775
/api/savedseach/4788
/new/user

What I would like to end up with

URLCOUNT
/login/2
/api/customer//data3

/weather/forecast/

1

/api/savedseach/

2

/new/user

1

 

Im using | stats count by URL
However as mentioned above my issue is with the URLs that have ids or guids in them

Labels (1)
0 Karma
1 Solution

dmarling
Builder

You can normalize the url with regular expression, but you will need to account for all of your use cases.  Here's an example regex based on the examples you provided:

| rex mode=sed field=URL "s/\/(customer|savedsearch)\/[^\e\/]+/\/\1\//g"

 

Here's a run anywhere example that shows how it works:

| makeresults
| eval URL="/login/
/login/
/api/customer/5542-a44/data
/api/customer/5c77-59w/data
/api/customer/7a88-134/data
/weather/forecast/
/api/savedsearch/7775
/api/savedsearch/4788
/new/use"
| makemv URL tokenizer="(?<URL>[^\n]+)"
| mvexpand URL
| rex mode=sed field=URL "s/\/(customer|savedsearch)\/[^\e\/]+/\/\1\//g"
| stats count by URL
If this comment/answer was helpful, please up vote it. Thank you.

View solution in original post

0 Karma

dmarling
Builder

You can normalize the url with regular expression, but you will need to account for all of your use cases.  Here's an example regex based on the examples you provided:

| rex mode=sed field=URL "s/\/(customer|savedsearch)\/[^\e\/]+/\/\1\//g"

 

Here's a run anywhere example that shows how it works:

| makeresults
| eval URL="/login/
/login/
/api/customer/5542-a44/data
/api/customer/5c77-59w/data
/api/customer/7a88-134/data
/weather/forecast/
/api/savedsearch/7775
/api/savedsearch/4788
/new/use"
| makemv URL tokenizer="(?<URL>[^\n]+)"
| mvexpand URL
| rex mode=sed field=URL "s/\/(customer|savedsearch)\/[^\e\/]+/\/\1\//g"
| stats count by URL
If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

gerard11
Engager

This is exactly what I was looking for, thank you.

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