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

How to extract values from response body

Yosi_Neuman
DynaMight Champion
DynaMight Champion

Hi guys, 

Customer asks to monitor OPEN APIC with synthetic so we create http checks with token saved in the vault.

The issue here is that the tokens got only 10 hours lifetime and we need to generate a new token with rest api every hour.

Our intension now is to call the rest api that generate the token on OPEN APIC and with value from the response body to set a value (with api.setValue(key, value)) for the next step which will send dynatrace vault rest api to change the value of the token to the new one.  

We need your help here with how to extract values from response body in the post execution step with response.getResponseBody() , how can we extract a value after token=" till the next " from the response body?

Thanks in advance

Yos 

dynatrace certificated professional - dynatrace primer partner - Matrix Soft Ware Division - Israel
4 REPLIES 4

Malaik
Helper

Hello

 

I think it's possible using Request Attributes

 

More details here Request Attributes 

Sharing Knowledge

Yosi_Neuman
DynaMight Champion
DynaMight Champion

Hi @Malaik 

Question is about post-execution script in http monitor.

How can we implement RA in http monitor?

Yos  

dynatrace certificated professional - dynatrace primer partner - Matrix Soft Ware Division - Israel

alvaro_sanchez
Dynatrace Advocate
Dynatrace Advocate

Hi Yosi,

 

As the response body is a string, I'd say using a regex match would do the trick, with a capture group somewhat like this (adapt it to the format of your token of course):

api.setValue("token", responseBody.match(new RegExp("token=\"([A-z0-9]+)\""))[1])

 

Regards,

Álvaro

Hi @alvaro_sanchez  

Great , will give it a try next week at customer site and will update !

Thanks a lot

Yos 

 

dynatrace certificated professional - dynatrace primer partner - Matrix Soft Ware Division - Israel