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!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...