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

post execution script - synthetic HTTP - multiple conditions

mariusz_kuczeba
Visitor

We are monitoring JSON status page for an app, where multiple checks return Healthy or Unhealthy as it's status.

I'm looking to somehow being able to tell which check fails exactly if my "Fail" condition will be "Unhealthy", and then be able to report on history of checks.

I understand that I should be able to do that with post-execution script. Via probably getting html response with response.getResponseBody();, somehow comparing it with my regex, and then returning message that's interesting for me with api.fail(). I'm missing matching examples to build such post-execution script myself. Anyone bothers enough to help me out?

Previously in SiteScope, I could cover that with regex, where while creating a regex condition, I could set a group with () that would be returned with error message.

 

Example response body:

{
"First": {
"status": "Healthy",
},
"Second": {
"status": "Unhealthy",
},
"Third": {
"status": "Healthy",
},
}

2 REPLIES 2

p_devulapalli
Champion

@mariusz_kuczeba - not the perfect one , but an example you can use

 

var responseBody = response.getResponseBody();
var data = JSON.parse(responseBody);
var unhealthyNodes = [];

// Iterate through the nodes for unhealthy
for (var node in data) {
    if (data[node].status === "Unhealthy") {
      unhealthyNodes.push(node);
    }
}

// If found, fail the request and return the node names
if (unhealthyNodes.length > 0) {
    api.fail("Unhealthy nodes found: " + unhealthyNodes.join(","));
} else {
    api.info("All nodes are healthy.");
}

 

Phani Devulapalli

There seem to be some issue in the script (always returns "All nodes are healthy."), but it's a great starting point for my anyway. Thanks!

Featured Posts