# Set success conditions for HTTP Monitor

**URL:** <https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor\
**Created:** [September 5, 2022, 7:52am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440 "2022-09-05T07:52:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![owen\_chen](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@owen\_chen](https://community.dynatrace.com/u/owen_chen)\
**Post date:** [September 5, 2022, 7:52am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/1 "2022-09-05T07:52:29Z")

</div>

Hi Everyone,

My client wants to regularly check whether some servers are running, so I set up HTTP Monitor to monitor, I only need to set IP: Port, if the status code returns 200, it is normal.

But I have a problem now. Our services are all configured with HA (High Availability), but one of the services has a special mechanism. If Service A is runnable, Service B will temporarily stop, so when I detect Service When B, the response Error code = 15 (Connection timeout).

 ![截圖 2022-09-05 下午3.48.59.png](https://global.discourse-cdn.com/dynatrace/original/2X/9/97f77a61caddf516d6ddd15e2e377c1f7adb9d63.png)

Is there any way to set the HTTP Monitor to one of Service A or B when the status code = 200, the HTTP monitor is considered successful?  
I have tried using Script but can’t seem to do the above?

Thanks,

Owen

---

<div class="post-metadata">

**Author:** ![NicolasT](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@NicolasT](https://community.dynatrace.com/u/NicolasT)\
**Post date:** [September 6, 2022, 8:46am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/2 "2022-09-06T08:46:36Z")

</div>

Hello,

here is an http synthetic (not browser) I made.

I got two web sites (say A and B). My use case :

- I would like to get at least one 200, if A is 200, global status ok, skip B

- If A is anything than 200, I try B

- If B is anything than 200, global status KO.

It looks quite similar as your need.

```markup
{
	"version": "1.0",
	"requests": [
		{
			"description": "https://www.mywebsite.fr/",
			"url": "https://www.mywebsite.fr/",
			"method": "GET",
			"configuration": {
				"acceptAnyCertificate": false,
				"followRedirects": false
			},
			"postProcessingScript": "if (response.getStatusCode() == 200 ) { api.skipNextSyntheticRequest(); } else if ( response.getStatusCode() == 302 ) { api.setValue(\"redirected\",\"1\"); }",
			"requestTimeout": 60
		},
		{
			"description": "https://www.mywebsite.de/",
			"url": "https://www.mywebsite.de/",
			"method": "GET",
			"configuration": {
				"acceptAnyCertificate": true,
				"followRedirects": false
			},
			"postProcessingScript": "if (response.getStatusCode() == 200 ) { api.finish(); } else if ( response.getStatusCode() == 302 && api.getValue(\"redirected\") == 1 ) { api.fail(\"Abnormal HTTP Redirect on two steps\");\n api.finish(); } else { api.fail(\"HTTP Failure on two steps\");\n api.finish(); }",
			"requestTimeout": 60
		}
	]
}

```

---

<div class="post-metadata">

**Author:** ![owen\_chen](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@owen\_chen](https://community.dynatrace.com/u/owen_chen)\
**Post date:** [September 6, 2022, 9:30am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/3 "2022-09-06T09:30:00Z")

</div>

[@NicolasT](https://community.dynatrace.com/user/40836)&nbsp;Thank you for your reply.

This is a good answer.  
However, the result of my test should be because the return code=15 I got, it doesn’t seem to be the status code, so I can’t enter “response.getStatusCode() !=200”.

Thanks again for your reply.

---

<div class="post-metadata">

**Author:** ![NicolasT](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@NicolasT](https://community.dynatrace.com/u/NicolasT)\
**Post date:** [September 6, 2022, 9:45am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/4 "2022-09-06T09:45:35Z")

</div>

I don’t get how to test the return code.

But, if you got no response, then you got no status code, so it’s null, or 0 or something different from 200 🙂&nbsp; The test should to the job ?

---

<div class="post-metadata">

**Author:** ![Jacek\_Janowicz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jacek_janowicz/32/38815_2.png) [@Jacek\_Janowicz](https://community.dynatrace.com/u/Jacek_Janowicz)\
**Post date:** [September 6, 2022, 11:03am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/5 "2022-09-06T11:03:30Z")

</div>

Hi&nbsp;[@owen\_chen](https://community.dynatrace.com/user/23144)

If my understanding is correct, from user point of view it is OK when either service A returns 200 or service B returns 200, Is that correct? Going further, I assume that your end users are perhaps not even aware that there are two different services running in HA mode, they just can receive (or not) expected response

If all above is true, how about totally different approach?

Instead of monitoring your service A and service B, perhaps you should try to monitor service / URL which is exposed to your final users?

Best Regards,

Jacek

---

<div class="post-metadata">

**Author:** ![NicolasT](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@NicolasT](https://community.dynatrace.com/u/NicolasT)\
**Post date:** [September 6, 2022, 1:19pm UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/6 "2022-09-06T13:19:34Z")

</div>

I agree with this pilosophy.

Rules for simple monitoring : What is the service furbished to the end users? Is it available or not , how do you simply monitor it?

They don’t care at all about the infrastructure layer and if unavailable, in this case, the causation will be trivial to get.

---

<div class="post-metadata">

**Author:** ![owen\_chen](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@owen\_chen](https://community.dynatrace.com/u/owen_chen)\
**Post date:** [September 7, 2022, 1:38am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/7 "2022-09-07T01:38:58Z")

</div>

Hi&nbsp;[@Jacek\_Janowicz](https://community.dynatrace.com/user/23019)&nbsp;,

Thank you for your reply.

I agree and have thought about it.

However, when I proposed this idea to my client, he said that because the private network segment where ActiveGate is located does not pass through the DNS server, the Domain name cannot be recognized, which is why I have to detect the A and B servers separately.

However, maybe I should be able to make ActiveGate recognize this Domain name?

Thanks,  
Owen

---

<div class="post-metadata">

**Author:** ![owen\_chen](https://avatars.discourse-cdn.com/v4/letter/o/3ab097/32.png) [@owen\_chen](https://community.dynatrace.com/u/owen_chen)\
**Post date:** [September 7, 2022, 2:15am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/8 "2022-09-07T02:15:32Z")

</div>

Hi&nbsp;[@NicolasT](https://community.dynatrace.com/user/40836)&nbsp;,

Thank you for your reply.

 ![截圖 2022-09-07 上午10.06.31.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/0/b026fdb5ab5ca709ad52de8ab995ca69ca208219.png)

I tried several conditional expressions with reference to the screenshot above, for example:  
response.getStatusCode() is Null  
response.getStatusCode() != 200  
response.getStatusCode() == 0  
But nothing seems to work.

I’m guessing that maybe “healthStatusCode” would be considered a failure if it were a few specific items.

---

<div class="post-metadata">

**Author:** ![NicolasT](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@NicolasT](https://community.dynatrace.com/u/NicolasT)\
**Post date:** [September 7, 2022, 7:00am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/9 "2022-09-07T07:00:59Z")

</div>

If this is a private internal website, you should think about a private activegate with correct access. That will solve your DNS issue.

---

<div class="post-metadata">

**Author:** ![Jacek\_Janowicz](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/jacek_janowicz/32/38815_2.png) [@Jacek\_Janowicz](https://community.dynatrace.com/u/Jacek_Janowicz)\
**Post date:** [September 7, 2022, 9:55am UTC](https://community.dynatrace.com/t/set-success-conditions-for-http-monitor/36440/10 "2022-09-07T09:55:59Z")

</div>

Hi [@owen\_chen](https://community.dynatrace.com/user/23144)

Adjusting AG, to be able to recognize domain name is one option of course.

But this case sounds to me like an extra reason for deploying your private location within the same segment of network, as your users. Not only should it solve DNS related problem, but additionally, this way results of synthetic tests will be even more accurate and trustworthy (since tests are executed from the same “place” and with the same network conditions, as applications end users have)

Best Regards,

Jacek
