11 Jul 2022 03:54 AM - edited 11 Jul 2022 03:57 AM
How to use the below javascript statement in a http monitor pre-execution script?
var reandomId = (["DDDDDDDD"]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16));
Solved! Go to Solution.
11 Jul 2022 11:49 AM
Hi,
What do you want to use the variable for? You can have a look at the documentation see what use cases we have for pre-execution scripts.
Sia
11 Jul 2022 03:17 PM - edited 11 Jul 2022 04:12 PM
Sia, I want to feed this variable to the request body.
I've referred to the documentation and couldn't figure out how to use this.
Script execution is getting failed.
Here is the link to the Synthetic HTTP Monitor script.
<Edited to remove the link>
Please check and let me know how to fix this.
11 Jul 2022 03:23 PM - edited 11 Jul 2022 03:25 PM
We don't recommend providing links to your monitors/ tenant in the public community. If you would like monitor specific advice I recommend that you open a chat or create a ticket.
That said, you can see the cause of the script failure by checking the vuc-http-execution.log of the ActiveGate that you ran the monitor on. I can see that the failure is due to "Pre script execution failed due to: ReferenceError: \"crypto\" is not defined. "
11 Jul 2022 03:27 PM
Hi @BhanuSarabu , for security reasons, we discourage posting direct links to Dynatrace environments, as this is a public forum. You can read more about it in our Community guidelines.
Could you post the screenshot of the script for the Synthetic HTTP Monitor instead?
11 Jul 2022 04:09 PM
Hi, Please find the details below:
1. I tested the script by passing the API request body in the pre-execution script and it worked fine.
var reqBody = "<api_req_body_json>"; request.setBody(reqBody); |
2. Now I want to feed an auto generated Id to the request body. As part of that, I've modified the pre-execution script as below and it's failing.
Note: At this point, I'm not passing the Id to the "reqBody" variable. I want to do that once this executes fine.
var reandomId = (["DDDDDDDD"]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); var reqBody = "<api_req_body_json>"; request.setBody(reqBody); |
Synthetic Monitor Script Name: Auto Feed ID Testing
Please let me know for more details.
19 Dec 2022 11:58 AM
Hello, @HannahM! Is this some workaround that would be helpful for this case? Thank you for your feedback in advance!
19 Dec 2022 01:58 PM - edited 19 Dec 2022 01:59 PM
If you would like to use the methods from the crypto library, you will need to add them to the pre-execution script, as it has no knowledge of it. You will need to paste all the code you need from the library into the pre/post execution script. There is a 50kb size limit for each pre/post-execution script, so be sure to use only the code you need and do a "minimize" on it.