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

HTTP Monitor--> How do I code an pre/post script to alert if 3 page checks fail with a variable?

runatyr
Guide

Hello:

I have created a synthetic http montior that is designed to check 3 web urls

For the sake of clarity lets call then

https://website-A 

https://website-B

https://website-C 

 

I have never used pre or post execution scripts and am not a programmer/scripter by any measure.

I contacted support and they said said "you need to figure out the code where you get a flag for each request and if all 3 fail then you mark it as a failure"

 

From a meta perspective I get what they are saying...

But I have no idea how that would be coded.

Could someone help? Maybe an example?

I thank you for looking at this post and any ideas or support from the community that is avaialble

 

 

3 REPLIES 3

HannahM
Dynatrace Leader
Dynatrace Leader

You could set a variable using api.setValue() if you consider the request to have failed then update it and then in the last request check the value of this variable after getting it (api.getValue()) and if it's showing there was a failure call api.fail().

var body = response.getResponseBody();
var res = JSON.parse(body);

if (res.flag < 1){
    api.setValue("flag", "failed");    
}

Is there a reason you want to do it this way? Our recommendation would be to use 3 separate monitors. It costs the same to make 3 separate requests in 1 HTTP monitor as it does to make 1 request in each of 3 HTTP Monitors.

If you want something more specific for your monitor raise a support ticket and we can work with your scenarios.

Best wishes, Hannah


Hannah :

Thank you so kindly for the insight.

I am not opposed to creating 3 separate monitors..The question that arises then however is

"How do i create a custom event that alerts if only all 3 monitors fail"?

If that is an option i certainly have no qualms

🙂


Update- I think that the one other factor to consider if doing 3 separate monitors is the timing

of all 3 monitors failing.

In the initial design with one monitor and 3 sites, all 3 are checked at the same time..


If 3 monitors are used, how do you coordinate them to all check at the same time like the single monitor described above?

HannahM
Dynatrace Leader
Dynatrace Leader

Ah, ok. Yeah for that use case I think you may have to do it the way you were suggesting. Sounds like a good Product Idea.

Featured Posts