17 May 2024 03:31 PM
In every http monitor, my first call is always to get an auth token. This step works fine. I pass it in the second step as the 'jwt' in the pre-execution step.
In two of my http monitors however, I also need to pass another header in pre-execution called ###-Api-Key. I have to pass the request body to that call. That is my jsonData being stringified, then passed to const hash. That's then returned and added to the api.addHeader.
I'm always getting the error UNKNOWN_METHOD_ERROR so hoping someone can take a look at this pre-execution script I've written, and help me get past this issue.
(Certain items changed for secure reasons)
Pre-execution script:
When looking at the execution details for more info on this error, I only get this:
//request
[
{
"requestId": "HTTP_CHECK_STEP-alpha-numericInfo",
"requestName": "send welcome message",
"sequenceNumber": 2,
"url": "",
"method": "",
"requestBody": "",
"requestHeaders": []
}
]
//response
[
{
"responseHeaders": [],
"responseBody": "",
"responseMessage": "",
"responseStatusCode": 0,
"responseSizeInBytes": 0,
"responseBodySizeLimitExceeded": false,
"failureMessage": ""
}
]
//execution
[
{
"visitId": "numericInfo",
"resolvedIps": [],
"healthStatusCode": 18,
"healthStatus": "UNKNOWN_METHOD_ERROR",
"peerCertificateDetails": "",
"redirectsCount": 0,
"peerCertificateExpiryDate": 0,
"processingMode": "STANDARD"
}
]
Solved! Go to Solution.
01 Jul 2024 12:17 PM
It looks like you are using CryptoJS.HmacSHA256 but haven' added this method to the pre-execution script. You can find information on adding this here
01 Jul 2024 01:31 PM - edited 01 Jul 2024 01:31 PM
This I did find a solution to, with the help of my Dynatrace team
In the pre-execution:
const jsonData=[{your data here}]
const stringData = JSON.stringify(jsonData);
request.setBody(stringData);
var CryptoJS=CryptoJS - HmacSHA256 code here
var CryptoJS=CryptoJS - Base64 code here
const key = "your key here";
const hash = CryptoJS.HmacSHA256(stringData, key);
const b64Hash = CryptoJS.enc.Base64.stringify(hash);
request.addHeader('Api-Key', b64Hash);
request.addHeader("Authorization", "Bearer " + api.getValue("jwt"));