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
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...