Splunk Search

Subtring from url field and then group using the url

arunprasadlv
Explorer

I have a field "BackendURL" which contains different url's.

for eg :

http://abc.com/emp?name=jim&no=101
http://abc.com/emp?name=tim&no=102
http://gef.com/vehicle

I am trying to generate a report by grouping the url's. Now when i group i want to uniquely identify the backend url , but ignore the queury params (anything after ?). I wrote this rex command to create a new field to substring the value before ? , but it does not work when the url does not contain "?" .

index="idx" Consumer|rex field=BackendURL "^(?.+?)\?"|stats count by BackendURL,url_noparams, host

Thanks and regards
Arun

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

index="idx" Consumer|rex field=BackendURL  "(?P<requestedUrl>(?P<path>https*:\/\/((?P<contextRoot>[^\/\s]+)\/)?([^\/\s\?;=]+\/)*)((?P<filename>[^\/\s\?;=]+))?|\-)" |stats count by BackendURL,requestedUrl , host

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this

index="idx" Consumer|rex field=BackendURL  "(?P<requestedUrl>(?P<path>https*:\/\/((?P<contextRoot>[^\/\s]+)\/)?([^\/\s\?;=]+\/)*)((?P<filename>[^\/\s\?;=]+))?|\-)" |stats count by BackendURL,requestedUrl , host
0 Karma

arunprasadlv
Explorer

Thanks a Lot. it worked!!

But I am struggling to understand the logic . Would you pls explain

Regards,
Arun

0 Karma

somesoni2
Revered Legend

I'm splitting the url to it's different portions

http://abc.com/emp?name=jim&no=101
|--Path------------------|
          |--contextroot-|
                          |-filename-| 
0 Karma

donB
Loves-to-Learn Lots

@somesoni2 Could you please help if the same url contextPath also has path params?

eg - i can have urls of 2 formats

http://abc.com/emp?name=jim&no=101
http://abc.com/car/ford
http://abc.com/car/tesla

here i need the count of uri paths like below

/car/{id} = 2

/emp = 1  (ignore query params)

 

0 Karma

somesoni2
Revered Legend

Give this a try

 

| makeresults | eval url="http://abc.com/test/emp?name=jim&no=101 http://abc.com/test/car/ford http://abc.com/test/car/tesla" | table url | makemv url | mvexpand url | eval url=replace(url,"\?","/") 
| rename "COMMENT" as "Above code generates sample data. Replace it with your query"
|rex field=url   "(?P<requestedUrl>(?P<path>https*:\/\/((?P<contextRoot>[^\/\s]+)\/)?([^\/\s\?;=]+\/)*)((?P<filename>[^\/\s\?;=]+))?|\-)" | stats count by path
0 Karma

arunprasadlv
Explorer

Got you. Thanks for the quick reply.

0 Karma

sundareshr
Legend

Try this
| eval baseURL=mvindex(split(BackendURL, "?"), o) | stats count by baseURL

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...