# Automated way to disable synthetic monitors for a particular time period

**URL:** <https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798>\
**Category:** Synthetic Monitoring\
**Tags:** synthetic-monitoring\
**Created:** [November 11, 2020, 6:58pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798 "2020-11-11T18:58:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [November 11, 2020, 6:58pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/1 "2020-11-11T18:58:19Z")

</div>

Hi Folks,

Is there a way we can disable the few selected synthetic monitors for the day of week and also enabled them back?

Basically, I’m looking to automate this task. I checked on synthetic API but we need to pass complete synthetic monitor JSON with “enabled” parameter as “false” or “true”.

I don’t want to use Maintenance window as it has some drawbacks.

Has anyone did this?

Regards,

AK

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [November 11, 2020, 7:57pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/2 "2020-11-11T19:57:55Z")

</div>

What you could do is repost your synthetic and pass the parameter of false instead of true:

 ![27286-1605124668187.png](https://global.discourse-cdn.com/dynatrace/original/3X/0/8/080c3f122da22c00b04aa296a1593eafd5c2b939.png)

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [November 11, 2020, 8:46pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/3 "2020-11-11T20:46:12Z")

</div>

At the moment, you should be able to do this through the API.

Please check out:

> **[snippets/api/synthetic/bulk-enable-disable-monitors at master ·...](https://github.com/Dynatrace/snippets/tree/master/api/synthetic/bulk-enable-disable-monitors)**
>
> master/api/synthetic/bulk-enable-disable-monitors

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [November 13, 2020, 9:52am UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/4 "2020-11-13T09:52:07Z")

</div>

Exellent. Thanks for this Antonio. It worked like a charm.

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [November 13, 2020, 9:52am UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/5 "2020-11-13T09:52:42Z")

</div>

Thank You Chad for your comments. I’m looking for some automated way to do it.

---

<div class="post-metadata">

**Author:** ![jshelby](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jshelby](https://community.dynatrace.com/u/jshelby)\
**Post date:** [November 17, 2020, 3:31pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/6 "2020-11-17T15:31:30Z")

</div>

We accomplished this by creating a Jenkins job that runs the commands to disable / enable at the desired times. We use a tag on designated the synthetics that are disables/enables.

---

<div class="post-metadata">

**Author:** ![rmeli](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rmeli](https://community.dynatrace.com/u/rmeli)\
**Post date:** [November 17, 2020, 7:33pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/7 "2020-11-17T19:33:12Z")

</div>

We also use tags to specify when a synthetic should be enabled/disabled and another job uses the API to do the enable/disable.

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [February 16, 2021, 2:51pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/8 "2021-02-16T14:51:02Z")

</div>

@[Antonio S.](https://answers.dynatrace.com/users/9493/view.html)

Script was working very well till now but it is started failing. Can you please help here?

Below is the error I’m receiving,

```auto
"E:\DynaTrace\Scipt.py", line 98, in <module>
    response = restApiGet(domain+"api/v1/synthetic/monitors?tag="+tag+"&Api-Token="+apiToken)
  File "E:\DynaTrace\Script.py", line 15, in restApiGet
    if int(response.headers['X-RateLimit-Remaining']) == 0:
  File "C:\Program Files\Python39\lib\site-packages\requests\structures.py", line 54, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-ratelimit-remaining'
waiting for 5 seconds
Reading contents of Error.log file

```

Is it the case that dynatrace API are not passing/using **x-ratelimit-remaining** header is now?

Regards,

AK

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [February 16, 2021, 3:38pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/9 "2021-02-16T15:38:41Z")

</div>

It looks like you might be experiencing some rate limiting. Take a look at:

> **[Dynatrace API - Access limit](https://docs.dynatrace.com/docs/dynatrace-api/basics/access-limit)**
>
> Find out about payload limits and request throttling that may affect your use of the Dynatrace API.

> **[What is API monitoring?](https://www.dynatrace.com/news/blog/what-is-api-monitoring/)**
>
> What is API monitoring? Learn more here about what it is and how it can help rapidly address application performance issues.

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [February 16, 2021, 5:52pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/10 "2021-02-16T17:52:20Z")

</div>

@[Antonio S.](https://answers.dynatrace.com/users/9493/view.html)

I tried it for just four monitors but its failing for them too.

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [February 16, 2021, 5:56pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/11 "2021-02-16T17:56:31Z")

</div>

Please beware that the rate limit applies for all API calls. Please check you are not using too much of them… If not, you should probably open a support case, or at least try the Chat.

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [February 18, 2021, 2:28pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/12 "2021-02-18T14:28:17Z")

</div>

Hi Antonio,

We came to know from support that,

```auto
Those throttling headers <strong>(X-RateLimit)</strong> will no longer in use from SaaS 1.210 version and new implementation now relies on a rapidly refreshing thread pool that processes API rather than a threshold of calls that is used per minute or hour.
And sleep time must be added based on the HTTP 429 response and then try again shortly after

```

In our python script (The one which is present on git), sleeping is added based on the **X-RateLimit-Reset** threshold.

I believe, adding random time.sleep won’t be appropriate.

Can you help or suggest, how we can adopt or modify the **time.sleep** based on HTTP 429 response or when throttling headers are not available?

Regards,

AK

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [February 18, 2021, 10:12pm UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/13 "2021-02-18T22:12:59Z")

</div>

Not sure about this new implementation… Did Support make any suggestion?

---

<div class="post-metadata">

**Author:** ![AK](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ak/32/164_2.png) [@AK](https://community.dynatrace.com/u/AK)\
**Post date:** [February 24, 2021, 6:12am UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/14 "2021-02-24T06:12:46Z")

</div>

It’s resolved. Support suggested to add,

```auto
if response.status_code == 429;
time.sleep(10);

```

Queue will get completed within 10 sec.

---

<div class="post-metadata">

**Author:** ![adam\_gardner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/adam_gardner/32/20087_2.png) [@adam\_gardner](https://community.dynatrace.com/u/adam_gardner)\
**Post date:** [February 24, 2021, 7:18am UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/15 "2021-02-24T07:18:44Z")

</div>

This is now available when you create a maintenance window (notice the toggle at the bottom of my image).

 ![28317-1614151098886.png](https://global.discourse-cdn.com/dynatrace/original/2X/6/64b1071d874c23b710dc837e937481d59f134242.png)

---

<div class="post-metadata">

**Author:** ![adam\_gardner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/adam_gardner/32/20087_2.png) [@adam\_gardner](https://community.dynatrace.com/u/adam_gardner)\
**Post date:** [February 24, 2021, 7:20am UTC](https://community.dynatrace.com/t/automated-way-to-disable-synthetic-monitors-for-a-particular-time-period/20798/16 "2021-02-24T07:20:20Z")

</div>

I’d highly recommend using our open source tool monaco rather than troubling yourself with scripting against our APIs 🙂 #makeyourlifeeasier

That said, see my other comment about this being available OOTB when you create maintenance windows now.

> **[GitHub - Dynatrace/dynatrace-configuration-as-code: This tool automates deployment of Dynatrace...](https://github.com/Dynatrace/dynatrace-configuration-as-code)**
>
> This tool automates deployment of Dynatrace Configuration to one or multiple Dynatrace environments.
