12 Mar 2025 09:00 AM
Hello everyone,
I'm encountering an issue with my Synthetic HTTP post-execution script and could use some help troubleshooting.
I have the following script where I define the responseBody directly within the code:
var responseBody = {
"db": [
{
"status": "UP",
"details": {
"db_name": "apig_otk",
"jdbc_name": "OAuth",
"metric_name": "count otk_sessionstore",
"metric_value": 61956,
"threshold": 2000000
}
},
{
"status": "UP",
"details": {
"db_name": "apig_ssg",
"jdbc_name": "SSG",
"metric_name": "count ssg_certificates",
"metric_value": 378,
"threshold": 490
}
},
{
"status": "DOWN",
"details": {
"db_name": "sm_SessionStore",
"jdbc_name": "SM_SessionStore",
"metric_name": "count sm_sessionspec5",
"metric_value": 79,
"threshold": 1000
}
},
{
"status": "UP",
"details": {
"db_name": "sm_SessionStore",
"jdbc_name": "SM_SessionStore",
"metric_name": "count sm_sessionvar5",
"metric_value": 155,
"threshold": 2000
}
}
]
};
With the above, the script works as expected, and I receive a failure message if the status is DOWN.
However, when I modify the script to dynamically retrieve the responseBody using the following lines:
//var responseBody = response.getResponseBody()
//var obj = JSON.parse(responseBody);
And replace the direct reference to responseBody with the parsed object obj, the script doesn't seem to generate any output. No failure message appears, and I can't figure out what's going wrong.
Here's what I'm trying:
var db_array = [];
var metric_name = [];
var metric_value = [];
// First loop to collect data
for (var i = 0; i < obj.db.length; i++) {
var db_var = obj.db[i];
var stato = db_var.status;
var dbName = db_var.details.db_name;
var metricName = db_var.details.metric_name;
var metricValue = db_var.details.metric_value;
// If status is DOWN, push data to arrays
if (stato === "DOWN") {
db_array.push(dbName);
metric_name.push(metricName);
metric_value.push(metricValue);
}
}
// If there are any DOWN dbs, signal the error
if (db_array.length > 0) {
api.fail("The following DBs have status 'DOWN': " + db_array.join() + " with '" + metric_name.join() + "' = " + metric_value.join());
} else {
api.info("All DBs are healthy!");
}
But this doesn't seem to be working. I don't get any failure message, and I’m unable to determine the root cause. Has anyone encountered this issue before, or can anyone point me in the right direction to fix it?
Thank you for any help!
Sofia