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

JSON Response - limit search top 20lines only- HTTP Monitor script

shahrukh_niazi
Contributor

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..

3 REPLIES 3

shahrukh_niazi
Contributor

shahrukh_niazi_0-1617143137089.pngshahrukh_niazi_1-1617143247394.png

 

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;

Synthetic SME and community advocate.

Michal_Gebacki
Community Team
Community Team

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!

Featured Posts