Getting Data In

get baseurl for different addresses

laurentiugrama
Explorer

In my logs I have different url and i need to fins a smart way to get the base_url.

The urls are:

  • /gw/api/request/assets?AccountId=710534357902&reportDate=2021-08-25     - I want to obtain  /gw/api/request/assets
  • /gw/api/oidc/client/v1     - I want to obtain  /gw/api/oidc/client/v1
  • /gw/api/oidc/client/v1/     - I want to obtain  /gw/api/oidc/client/v1
  • /gw/api/AccountOpenings/423423423-32sdf-34243    - I want to obtain /gw/api/AccountOpenings
  • /gw/api/AccountOpenings/345645fgh5-54hju-45565- I want to obtain /gw/api/AccountOpenings

Can I use a single regexp to do that ?

Now I use something like this but I don't think that is the right way

 

| eval a=split(URL,"?")|eval URL=mvindex(a,0)
| rex field=URL "(?<base_url>.*AccountOpenings/v[0-9]).*"
| eval URL=if(match(URL,"AccountOpenings" ),base_url,URL)

 

 

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| rex field=URL "(?<base_url>.+(\/v[0-9]|AccountOpenings|(?=\?)))"

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| rex field=URL "(?<base_url>.+(\/v[0-9]|AccountOpenings|(?=\?)))"

laurentiugrama
Explorer

Thank you for the solution. It helps me a lot.

It seems that that the url ended in "/" it's not treated but I will try to find a solution

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...