30 Mar 2021 11:20 PM - last edited on 27 May 2021 03:00 PM by MaciejNeumann
We have a swagger API which outputs a JSON response that has status detail about the execution of our batchjob.
In my post execution script of HTTPMonitor of Dynatrace synthetics, I have this logic
responseObject = JSON.parse(response.getResponseBody());
responseObject.runs.forEach(x => {
if (x.success != true) {
api.fail(x.id + " failed");
}
});
Batch jobs runs once a day. Our swagger JSON response has status details of last 50executions in the JSON body. I'm only interested in the 0 response - which has the status info of basically today's execution & ignore all the rest. The above logic works when last 50th execution has no "success :fail" in them
Anyone knows how to limit the search in post execution script of an HTTP Monitor to only look for 0 iteration, or , search first 20lines only & ignore rest of the JSON payload, and if you find "success :true" that means batch job ran successfully. Because first 20 lines has the last execution detail in it..
Solved! Go to Solution.
25 Apr 2022 01:54 PM
You can parse the response body as json. I guess you'd want something like:
var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);
var ps=jsonData.runs[0].success;
22 Apr 2022 10:14 AM
Hello everyone!
This thread is left unanswered so far, but maybe somebody would find anything that would help anyone who faces similar issue like mentioned above now or in future?
Thank you in advance for any feedback!