healthchecks_healthchecks/templates/docs/cloning_checks.html-fragment
2023-08-11 11:18:49 +03:00

29 lines
2.8 KiB
Plaintext

<h1>Cloning Checks</h1>
<p>You can clone individual checks from the "Check Details"
page:</p>
<p><img alt="The &quot;Create a Copy&quot; button" src="IMG_URL/create_copy.png" /></p>
<p>The "Create a Copy..." function creates a new check in the same project and copies
over the following:</p>
<ul>
<li>Name, tags, description</li>
<li>Schedule</li>
<li>Assigned notification methods</li>
</ul>
<p>The newly created check has a different ping URL and an empty event log.</p>
<h2>Cloning All Checks Into a New Project</h2>
<p>It is sometimes useful to clone an entire project. For example, when recreating
an existing deployment in a new region. The SITE_NAME web interface does
not have a function to clone an entire project, but you can clone all checks in the
project relatively easily using the <a href="../api/">Management API</a> calls.
Below is an example using Python and the <a href="https://requests.readthedocs.io/en/master/">requests</a> library:</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
<span class="n">API_URL</span> <span class="o">=</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/&quot;</span>
<span class="n">SOURCE_PROJECT_READONLY_KEY</span> <span class="o">=</span> <span class="s2">&quot;...&quot;</span>
<span class="n">TARGET_PROJECT_KEY</span> <span class="o">=</span> <span class="s2">&quot;...&quot;</span>
<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>
<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>
<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>
<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>
</code></pre></div>