Splunk Search

extract field from url skipping the ids

artemdubrov
Engager

i have urls that include numeric ids in the path:

/api/clients/11111/interactions
/api/clients/22222/interactions
/api/clients/33333/profiles

I need to extract service_name field, skipping the ids, ideally:

| service_name              | count |
|---------------------------+-------|
| /api/clients/interactions |     2 |
| /api/clients/profiles     |     1 |

please help

Labels (2)
Tags (1)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval url="/api/clients/11111/interactions,/api/clients/22222/interactions,/api/clients/33333/profiles" 
| makemv delim="," url 
| mvexpand url 
| rex mode=sed field=url "s/\/\w+//3" 
| rename url as service_name 
| stats count by service_name

View solution in original post

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval url="/api/clients/11111/interactions,/api/clients/22222/interactions,/api/clients/33333/profiles" 
| makemv delim="," url 
| mvexpand url 
| rex mode=sed field=url "s/\/\w+//3" 
| rename url as service_name 
| stats count by service_name

artemdubrov
Engager

that works exactly as requested, thanks!

i guess my challenge is how to put it inside "field extractor" so I can use the 'service_name' field and all the logic is hidden in that field definition.
https://docs.splunk.com/Documentation/Splunk/8.0.3/Knowledge/ExtractfieldsinteractivelywithIFX

I think I was able to accomplish it by using 'Calculated fields' defined as:
replace(service_name, "/\d+", "")

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...