cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Replace certain part of URL in a log content

susmita_k
Organizer

I have a log content like this :

URL: /v1/agreements/12345678/vins/xx123456KL456/validate

How can I replace the 3rd and 5th portion so that for all vins and agreements # dynatrace treat them as same url ?

4 REPLIES 4

KeeganNelson
Dynatrace Advisor
Dynatrace Advisor

I would recommend using the DPL architect after clicking on this specific field and choosing extract. This will allow you to parse the information and then represent it in a new field. 

Here are the docs on this, DPL Architect — Dynatrace Docs

Mohammed-Samy
Visitor

Hello @susmita_k

you can try the DQL replace pattern

data record(content="URL: /v1/agreements/12345678/vins/xx123456KL456/validate")
| fieldsAdd content = replacePattern(content, "'agreements/' ld '/'", "agreements/***/")
| fieldsAdd content = replacePattern(content, "'vins/' ld '/'", "vins/***/")

 Output : URL: /v1/agreements/***/vins/***/validate

here's the documentation reference: replacePattern 

 

I have multiple type of urls and i would like to do it dynamically.. also, when I do it, I dont want it to update the v1 or v2s present in the url. while replacepattern is working, but not able to do it for all type of url with single line of code.

if you have some sort of pattern for these URLs you can identify them using dpl and replace them even if there's some slight differences you can use the or operator to pick one variant 

for example if we have these 3 patterns :

URL: /v1/agreements/12345678/vins/xx123456KL456/validate
URL: /v1/agreements1/12345678/vins/xx123456KL456/validate
URL: /v1/agreements2/12345678/vins/xx123456KL456/validate

data record(content="URL: /v1/agreements/12345678/vins/xx123456KL456/validate"),
record(content="URL: /v1/agreements1/12345678/vins/xx123456KL456/validate"),
record(content="URL: /v1/agreements2/12345678/vins/xx123456KL456/validate")
| fieldsAdd content = replacePattern(content, "('agreements/' | 'agreements1/' | 'agreements2/') ld '/'", "agreements/***/")
| fieldsAdd content = replacePattern(content, "'vins/' ld '/'", "vins/***/")

you can make them in a single line of code but then it will be more sensitive to any pattern change

Featured Posts