You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
2.8 KiB

4 years ago
4 years ago
  1. <h1>Cloning Checks</h1>
  2. <p>You can clone individual checks from the "Check Details"
  3. page:</p>
  4. <p><img alt="The &quot;Create a Copy&quot; button" src="IMG_URL/create_copy.png" /></p>
  5. <p>The "Create a Copy..." function creates a new check in the same project and copies
  6. over the following:</p>
  7. <ul>
  8. <li>Name, tags, description</li>
  9. <li>Schedule</li>
  10. <li>Assigned notification methods</li>
  11. </ul>
  12. <p>The newly created check has a different ping URL, and it starts with an empty log.</p>
  13. <h2>Cloning All Checks Into a New Project</h2>
  14. <p>It is sometimes useful to clone an entire project. For example, when recreating
  15. an existing deployment in a new region. The SITE_NAME web interface does
  16. not have a function to clone an entire project, but you can clone all checks in the
  17. project relatively easily using the <a href="../api/">Management API</a> calls.
  18. Below is an example using Python and the <a href="https://requests.readthedocs.io/en/master/">requests</a> library:</p>
  19. <div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
  20. <span class="n">API_URL</span> <span class="o">=</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/&quot;</span>
  21. <span class="n">SOURCE_PROJECT_READONLY_KEY</span> <span class="o">=</span> <span class="s2">&quot;...&quot;</span>
  22. <span class="n">TARGET_PROJECT_KEY</span> <span class="o">=</span> <span class="s2">&quot;...&quot;</span>
  23. <span class="n">r</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">API_URL</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;X-Api-Key&quot;</span><span class="p">:</span> <span class="n">SOURCE_PROJECT_READONLY_KEY</span><span class="p">})</span>
  24. <span class="k">for</span> <span class="n">check</span> <span class="ow">in</span> <span class="n">r</span><span class="o">.</span><span class="n">json</span><span class="p">()[</span><span class="s2">&quot;checks&quot;</span><span class="p">]:</span>
  25. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Cloning </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">check</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
  26. <span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">API_URL</span><span class="p">,</span> <span class="n">json</span><span class="o">=</span><span class="n">check</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;X-Api-Key&quot;</span><span class="p">:</span> <span class="n">TARGET_PROJECT_KEY</span><span class="p">})</span>
  27. </code></pre></div>