Browse Source

render_docs

pull/394/head
Pēteris Caune 4 years ago
parent
commit
5b3928ce79
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
14 changed files with 118 additions and 118 deletions
  1. +44
    -44
      templates/docs/api.html
  2. +6
    -6
      templates/docs/attaching_logs.html
  3. +8
    -8
      templates/docs/bash.html
  4. +3
    -3
      templates/docs/cloning_checks.html
  5. +2
    -2
      templates/docs/csharp.html
  6. +18
    -18
      templates/docs/http_api.html
  7. +4
    -4
      templates/docs/javascript.html
  8. +3
    -3
      templates/docs/measuring_script_run_time.html
  9. +6
    -6
      templates/docs/monitoring_cron_jobs.html
  10. +2
    -2
      templates/docs/php.html
  11. +6
    -6
      templates/docs/powershell.html
  12. +8
    -8
      templates/docs/python.html
  13. +2
    -2
      templates/docs/ruby.html
  14. +6
    -6
      templates/docs/signalling_failures.html

+ 44
- 44
templates/docs/api.html View File

@ -113,12 +113,12 @@ specified value.</p>
<dd>The API key is either missing or invalid.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/checks/
</pre></div>
<div class="highlight"><pre><span></span><code>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/checks/
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;checks&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Filesystem Backup&quot;</span><span class="p">,</span>
@ -155,13 +155,13 @@ specified value.</p>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<p>When using the read-only API key, the following fields are omitted:
<code>ping_url</code>, <code>update_url</code>, <code>pause_url</code>, <code>channels</code>. An extra <code>unique_key</code> field
is added which can be used <a href="#get-check">to <code>GET</code> a check</a> in place of the <code>UUID</code>. The <code>unique_key</code> identifier is stable across API calls. Example:</p>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;checks&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Filesystem Backup&quot;</span><span class="p">,</span>
@ -192,7 +192,7 @@ is added which can be used <a href="#get-check">to <code>GET</code> a check</a>
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="get-check">Get a Single Check</h2>
@ -213,12 +213,12 @@ using the read-only API key) as an identifier.</p>
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/checks/&lt;uuid&gt;
</pre></div>
<div class="highlight"><pre><span></span><code>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/checks/&lt;uuid&gt;
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Database Backup&quot;</span><span class="p">,</span>
<span class="nt">&quot;tags&quot;</span><span class="p">:</span> <span class="s2">&quot;production db&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;Runs ~/db-backup.sh&quot;</span><span class="p">,</span>
@ -235,7 +235,7 @@ using the read-only API key) as an identifier.</p>
<span class="nt">&quot;schedule&quot;</span><span class="p">:</span> <span class="s2">&quot;15 5 * * *&quot;</span><span class="p">,</span>
<span class="nt">&quot;tz&quot;</span><span class="p">:</span> <span class="s2">&quot;UTC&quot;</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h3>Example Read-Only Response</h3>
@ -245,7 +245,7 @@ added. This identifier is stable across API calls.</p>
<p>Note: the <code>ping_url</code>, <code>update_url</code> and <code>pause_url</code> fields, although omitted, are not
really secret. The client already knows the check's unique UUID and so can easily
construct these URLs by itself.</p>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;Database Backup&quot;</span><span class="p">,</span>
<span class="nt">&quot;tags&quot;</span><span class="p">:</span> <span class="s2">&quot;production db&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;Runs ~/db-backup.sh&quot;</span><span class="p">,</span>
@ -259,7 +259,7 @@ construct these URLs by itself.</p>
<span class="nt">&quot;schedule&quot;</span><span class="p">:</span> <span class="s2">&quot;15 5 * * *&quot;</span><span class="p">,</span>
<span class="nt">&quot;tz&quot;</span><span class="p">:</span> <span class="s2">&quot;UTC&quot;</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="create-check">Create a Check</h2>
@ -371,20 +371,20 @@ field values.</dd>
the limit is 20 checks per account.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/ <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/ <span class="se">\</span>
--header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> <span class="se">\</span>
--data <span class="s1">&#39;{&quot;name&quot;: &quot;Backups&quot;, &quot;tags&quot;: &quot;prod www&quot;, &quot;timeout&quot;: 3600, &quot;grace&quot;: 60}&#39;</span>
</pre></div>
</code></pre></div>
<p>Or, alternatively:</p>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/ <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/ <span class="se">\</span>
--data <span class="s1">&#39;{&quot;api_key&quot;: &quot;your-api-key&quot;, &quot;name&quot;: &quot;Backups&quot;, &quot;tags&quot;: &quot;prod www&quot;, &quot;timeout&quot;: 3600, &quot;grace&quot;: 60}&#39;</span>
</pre></div>
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;channels&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;grace&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
@ -400,7 +400,7 @@ the limit is 20 checks per account.</dd>
<span class="nt">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">3600</span><span class="p">,</span>
<span class="nt">&quot;update_url&quot;</span><span class="p">:</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="update-check">Update an Existing Check</h2>
@ -495,20 +495,20 @@ field values.</dd>
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
--header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> <span class="se">\</span>
--data <span class="s1">&#39;{&quot;name&quot;: &quot;Backups&quot;, &quot;tags&quot;: &quot;prod www&quot;, &quot;timeout&quot;: 3600, &quot;grace&quot;: 60}&#39;</span>
</pre></div>
</code></pre></div>
<p>Or, alternatively:</p>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
--data <span class="s1">&#39;{&quot;api_key&quot;: &quot;your-api-key&quot;, &quot;name&quot;: &quot;Backups&quot;, &quot;tags&quot;: &quot;prod www&quot;, &quot;timeout&quot;: 3600, &quot;grace&quot;: 60}&#39;</span>
</pre></div>
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;channels&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;grace&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
@ -524,7 +524,7 @@ field values.</dd>
<span class="nt">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">3600</span><span class="p">,</span>
<span class="nt">&quot;update_url&quot;</span><span class="p">:</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="pause-check">Pause Monitoring of a Check</h2>
@ -544,16 +544,16 @@ state. You can resume monitoring of the check by pinging it.</p>
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/0c8983c9-9d73-446f-adb5-0641fdacc9d4/pause <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/0c8983c9-9d73-446f-adb5-0641fdacc9d4/pause <span class="se">\</span>
--request POST --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> --data <span class="s2">&quot;&quot;</span>
</pre></div>
</code></pre></div>
<p>Note: the <code>--data ""</code> argument forces curl to send a <code>Content-Length</code> request header
even though the request body is empty. For HTTP POST requests, the <code>Content-Length</code>
header is sometimes required by some network proxies and web servers.</p>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;channels&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;grace&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
@ -569,7 +569,7 @@ header is sometimes required by some network proxies and web servers.</p>
<span class="nt">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">3600</span><span class="p">,</span>
<span class="nt">&quot;update_url&quot;</span><span class="p">:</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc&quot;</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="delete-check">Delete Check</h2>
@ -589,13 +589,13 @@ check that was just deleted.</p>
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc <span class="se">\</span>
--request DELETE --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span>
</pre></div>
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;channels&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;desc&quot;</span><span class="p">:</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="nt">&quot;grace&quot;</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span>
@ -611,7 +611,7 @@ check that was just deleted.</p>
<span class="nt">&quot;timeout&quot;</span><span class="p">:</span> <span class="mi">3600</span><span class="p">,</span>
<span class="nt">&quot;update_url&quot;</span><span class="p">:</span> <span class="s2">&quot;SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc&quot;</span><span class="p">,</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="list-pings">Get a list of check's logged pings</h2>
@ -632,13 +632,13 @@ number of returned pings depends on account's billing plan: 100 for free account
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pings/ <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pings/ <span class="se">\</span>
--header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span>
</pre></div>
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;pings&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;success&quot;</span><span class="p">,</span>
@ -680,7 +680,7 @@ number of returned pings depends on account's billing plan: 100 for free account
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="list-flips">Get a list of check's status changes</h2>
@ -723,13 +723,13 @@ number of returned pings depends on account's billing plan: 100 for free account
<dd>The specified check does not exist.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/flips/ <span class="se">\</span>
<div class="highlight"><pre><span></span><code>curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/flips/ <span class="se">\</span>
--header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span>
</pre></div>
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">[</span>
<div class="highlight"><pre><span></span><code><span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;timestamp&quot;</span><span class="p">:</span> <span class="s2">&quot;2020-03-23T10:18:23+00:00&quot;</span><span class="p">,</span>
<span class="nt">&quot;up&quot;</span><span class="p">:</span> <span class="mi">1</span>
@ -743,7 +743,7 @@ number of returned pings depends on account's billing plan: 100 for free account
<span class="nt">&quot;up&quot;</span><span class="p">:</span> <span class="mi">1</span>
<span class="p">}</span>
<span class="p">]</span>
</pre></div>
</code></pre></div>
<h2 class="rule" id="list-channels">Get a List of Existing Integrations</h2>
@ -757,12 +757,12 @@ number of returned pings depends on account's billing plan: 100 for free account
<dd>The API key is either missing or invalid.</dd>
</dl>
<h3>Example Request</h3>
<div class="highlight"><pre><span></span>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/channels/
</pre></div>
<div class="highlight"><pre><span></span><code>curl --header <span class="s2">&quot;X-Api-Key: your-api-key&quot;</span> SITE_ROOT/api/v1/channels/
</code></pre></div>
<h3>Example Response</h3>
<div class="highlight"><pre><span></span><span class="p">{</span>
<div class="highlight"><pre><span></span><code><span class="p">{</span>
<span class="nt">&quot;channels&quot;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nt">&quot;id&quot;</span><span class="p">:</span> <span class="s2">&quot;4ec5a071-2d08-4baa-898a-eb4eb3cd6941&quot;</span><span class="p">,</span>
@ -776,4 +776,4 @@ number of returned pings depends on account's billing plan: 100 for free account
<span class="p">}</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>

+ 6
- 6
templates/docs/attaching_logs.html View File

@ -6,17 +6,17 @@ the request body, so you can inspect it later.</p>
<h2>Logging Command Output</h2>
<p>In this example, we run <code>certbot renew</code>, capture its output, and submit
the captured output to SITE_NAME:</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/sh</span>
<span class="nv">m</span><span class="o">=</span><span class="k">$(</span>/usr/bin/certbot renew <span class="m">2</span>&gt;<span class="p">&amp;</span><span class="m">1</span><span class="k">)</span>
curl -fsS --retry <span class="m">3</span> --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> PING_URL
</pre></div>
</code></pre></div>
<h2>In Combination with the <code>/fail</code> Endpoint</h2>
<p>We can extend the previous example and signal either success or failure
depending on the exit code:</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/sh</span>
<span class="nv">url</span><span class="o">=</span>PING_URL
@ -24,11 +24,11 @@ depending on the exit code:</p>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span> <span class="nv">url</span><span class="o">=</span><span class="nv">$url</span>/fail<span class="p">;</span> <span class="k">fi</span>
curl -fsS --retry <span class="m">3</span> --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> <span class="nv">$url</span>
</pre></div>
</code></pre></div>
<h2>All in One Line</h2>
<p>Finally, all of the above can be packaged in a single line. The one-line
version can be put directly in crontab, without using a wrapper script.</p>
<div class="highlight"><pre><span></span><span class="nv">m</span><span class="o">=</span><span class="k">$(</span>/usr/bin/certbot renew <span class="m">2</span>&gt;<span class="p">&amp;</span><span class="m">1</span><span class="k">)</span><span class="p">;</span> curl -fsS --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> <span class="s2">&quot;PING_URL</span><span class="k">$(</span><span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nb">echo</span> -n /fail<span class="k">)</span><span class="s2">&quot;</span>
</pre></div>
<div class="highlight"><pre><span></span><code><span class="nv">m</span><span class="o">=</span><span class="k">$(</span>/usr/bin/certbot renew <span class="m">2</span>&gt;<span class="p">&amp;</span><span class="m">1</span><span class="k">)</span><span class="p">;</span> curl -fsS --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> <span class="s2">&quot;PING_URL</span><span class="k">$(</span><span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nb">echo</span> -n /fail<span class="k">)</span><span class="s2">&quot;</span>
</code></pre></div>

+ 8
- 8
templates/docs/bash.html View File

@ -4,7 +4,7 @@ have to do is make a HTTP request at the end of the script.
<a href="https://curl.haxx.se/docs/manpage.html">curl</a> and
<a href="https://www.gnu.org/software/wget/manual/wget.html">wget</a>
are two common command line HTTP clients you can use.</p>
<div class="highlight"><pre><span></span><span class="c1"># Sending a HTTP GET request with curl:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># Sending a HTTP GET request with curl:</span>
curl --retry <span class="m">3</span> PING_URL
<span class="c1"># Silent version (no stdout/stderr output unless curl hits an error):</span>
@ -12,7 +12,7 @@ curl -fsS --retry <span class="m">3</span> PING_URL
<span class="c1"># Sending a HTTP GET request with wget:</span>
wget PING_URL -O /dev/null
</pre></div>
</code></pre></div>
<h2>Signalling Failure from Shell Scripts</h2>
@ -23,13 +23,13 @@ signal a failure. The below example:</p>
<li>if the certbot command is successful (exit code 0), send HTTP GET to <code>PING_URL</code></li>
<li>otherwise, send HTTP GET to <code>PING_URL/fail</code></li>
</ul>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/sh</span>
<span class="c1"># Payload here:</span>
/usr/bin/certbot renew
<span class="c1"># Ping SITE_NAME</span>
curl --retry <span class="m">3</span> <span class="s2">&quot;PING_URL</span><span class="k">$(</span><span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nb">echo</span> -n /fail<span class="k">)</span><span class="s2">&quot;</span>
</pre></div>
</code></pre></div>
<h2>Logging Command Output</h2>
@ -37,11 +37,11 @@ curl --retry <span class="m">3</span> <span class="s2">&quot;PING_URL</span><spa
body. If the request body looks like a valid UTF-8 string, SITE_NAME
will accept and store first 10KB of the request body.</p>
<p>In the below example, certbot's output is captured and submitted via HTTP POST:</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/sh</span>
<span class="nv">m</span><span class="o">=</span><span class="k">$(</span>/usr/bin/certbot renew <span class="m">2</span>&gt;<span class="p">&amp;</span><span class="m">1</span><span class="k">)</span>
curl -fsS --retry <span class="m">3</span> --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> PING_URL
</pre></div>
</code></pre></div>
<h2>Auto-provisioning New Checks</h2>
@ -49,7 +49,7 @@ curl -fsS --retry <span class="m">3</span> --data-raw <span class="s2">&quot;</s
(if it does not already exist) and to retrieve its ping URL.
Using this technique, you can write services that automatically
register with SITE_NAME the first time they run.</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/bash</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/bash</span>
<span class="nv">API_KEY</span><span class="o">=</span>your-api-key-here
@ -62,4 +62,4 @@ register with SITE_NAME the first time they run.</p>
<span class="c1"># Finally, send a ping:</span>
curl --retry <span class="m">3</span> <span class="nv">$URL</span>
</pre></div>
</code></pre></div>

+ 3
- 3
templates/docs/cloning_checks.html View File

@ -16,7 +16,7 @@ an existing deployment in a new region. The SITE_NAME web interface does
not have a function to clone an entire project, but this can be done relatively
easily using the <a href="../api/">Management API</a> calls. Below is an example using Python
and the requests library:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<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>
@ -24,6 +24,6 @@ and the requests library:</p>
<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="k">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="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>
</pre></div>
</code></pre></div>

+ 2
- 2
templates/docs/csharp.html View File

@ -1,7 +1,7 @@
<h1>C</h1>
<p>Below is an example of making a HTTP request to SITE_NAME from C#.</p>
<div class="highlight"><pre><span></span><span class="k">using</span> <span class="p">(</span><span class="kt">var</span> <span class="n">client</span> <span class="p">=</span> <span class="k">new</span> <span class="n">System</span><span class="p">.</span><span class="n">Net</span><span class="p">.</span><span class="n">WebClient</span><span class="p">())</span>
<div class="highlight"><pre><span></span><code><span class="k">using</span> <span class="p">(</span><span class="kt">var</span> <span class="n">client</span> <span class="p">=</span> <span class="k">new</span> <span class="n">System</span><span class="p">.</span><span class="n">Net</span><span class="p">.</span><span class="n">WebClient</span><span class="p">())</span>
<span class="p">{</span>
<span class="n">client</span><span class="p">.</span><span class="n">DownloadString</span><span class="p">(</span><span class="s">&quot;PING_URL&quot;</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</code></pre></div>

+ 18
- 18
templates/docs/http_api.html View File

@ -15,20 +15,20 @@ If the request body looks like a UTF-8 string, SITE_NAME stores the request body
<p>Successful responses will have the "200 OK" HTTP response status code and a short
and simple string "OK" in the response body.</p>
<h2>Signal Success ("ping")</h2>
<div class="highlight"><pre><span></span>HEAD|GET|POST PING_ENDPOINT{uuid}
</pre></div>
<div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT{uuid}
</code></pre></div>
<p>Signals to SITE_NAME that the job has completed successfully (or, for
continuously running processes, is still running and healthy). The <code>uuid</code> parameter
is unique for each check.</p>
<p><strong>Example</strong></p>
<div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
</pre></div>
</code></pre></div>
<div class="highlight"><pre><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
<span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
@ -37,23 +37,23 @@ is unique for each check.</p>
<span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
OK
</pre></div>
</code></pre></div>
<h2>Signal Failure</h2>
<div class="highlight"><pre><span></span>HEAD|GET|POST PING_ENDPOINT{uuid}/fail
</pre></div>
<div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT{uuid}/fail
</code></pre></div>
<p>Signals to SITE_NAME that the job has failed. Actively signalling a failure
minimizes the delay from your monitored service failing to you receiving an alert.</p>
<p><strong>Example</strong></p>
<div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/fail</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/fail</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
</pre></div>
</code></pre></div>
<div class="highlight"><pre><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
<span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
@ -62,12 +62,12 @@ minimizes the delay from your monitored service failing to you receiving an aler
<span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
OK
</pre></div>
</code></pre></div>
<h2>Signal a Start</h2>
<div class="highlight"><pre><span></span>HEAD|GET|POST PING_ENDPOINT{uuid}/start
</pre></div>
<div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT{uuid}/start
</code></pre></div>
<p>Sends a "job has started!" message to SITE_NAME. This is
@ -77,12 +77,12 @@ optional but enables a few extra features:</p>
<li>SITE_NAME will detect if the job runs longer than its configured grace time</li>
</ul>
<p><strong>Example</strong></p>
<div class="highlight"><pre><span></span><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/start</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/start</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
<span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
</pre></div>
</code></pre></div>
<div class="highlight"><pre><span></span><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
<span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
<span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
<span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
@ -91,4 +91,4 @@ optional but enables a few extra features:</p>
<span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
OK
</pre></div>
</code></pre></div>

+ 4
- 4
templates/docs/javascript.html View File

@ -1,13 +1,13 @@
<h1>Javascript</h1>
<p>Below is an example of making a HTTP request to SITE_NAME from Node.js.</p>
<div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span>
<div class="highlight"><pre><span></span><code><span class="kd">var</span> <span class="nx">https</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;https&#39;</span><span class="p">);</span>
<span class="nx">https</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">);</span>
</pre></div>
</code></pre></div>
<p>You can also send pings from a browser environment. SITE_NAME sets the
<code>Access-Control-Allow-Origin:*</code> CORS header, so cross-domain AJAX requests work.</p>
<div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">xhr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">();</span>
<div class="highlight"><pre><span></span><code><span class="kd">var</span> <span class="nx">xhr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XMLHttpRequest</span><span class="p">();</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="s1">&#39;PING_URL&#39;</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="kc">null</span><span class="p">);</span>
</pre></div>
</code></pre></div>

+ 3
- 3
templates/docs/measuring_script_run_time.html View File

@ -7,7 +7,7 @@
<p>Signalling a start kicks off a separate timer: the job now <strong>must</strong> signal a
success within its configured "Grace Time", or it will get marked as "down".</p>
<p>Below is a code example in Python:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
<span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;PING_URL&quot;</span>
@ -23,11 +23,11 @@ success within its configured "Grace Time", or it will get marked as "down".</p>
<span class="c1"># TODO: run the job here</span>
<span class="n">fib</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="k">if</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="k">else</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">fib</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s2">&quot;F(42) = </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">fib</span><span class="p">(</span><span class="mi">42</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;F(42) = </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">fib</span><span class="p">(</span><span class="mi">42</span><span class="p">))</span>
<span class="c1"># Signal success:</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">URL</span><span class="p">)</span>
</pre></div>
</code></pre></div>
<h2>Viewing Measured Run Times</h2>


+ 6
- 6
templates/docs/monitoring_cron_jobs.html View File

@ -3,10 +3,10 @@
update your cron job command to send a HTTP request to SITE_NAME
after a job completes.</p>
<p>Let's look at an example:</p>
<div class="highlight"><pre><span></span>$ crontab -l
<div class="highlight"><pre><span></span><code>$ crontab -l
<span class="c1"># m h dom mon dow command</span>
<span class="m">8</span> <span class="m">6</span> * * * /home/user/backup.sh
</pre></div>
</code></pre></div>
<p>The above job runs <code>/home/user/backup.sh</code> every day at 6:08. The backup
@ -40,10 +40,10 @@ increasingly important as you add more checks to your account.</p>
</ol>
<p>Finally, edit your cron job definition and append a curl or wget call
after the command:</p>
<div class="highlight"><pre><span></span>$ crontab -e
<div class="highlight"><pre><span></span><code>$ crontab -e
<span class="c1"># m h dom mon dow command</span>
<span class="m">8</span> <span class="m">6</span> * * * /home/user/backup.sh <span class="o">&amp;&amp;</span> curl -fsS --retry <span class="m">3</span> -o /dev/null PING_URL
</pre></div>
</code></pre></div>
<p>Now, each time your cron job runs, it will send a HTTP request to the ping URL.
@ -101,7 +101,7 @@ there is an error. Feel free to adjust the curl options to suit your needs.</p>
<h2>Looking up Your Machine's Time Zone</h2>
<p>On modern GNU/Linux systems, you can look up the time zone using the
<code>timedatectl status</code> command and looking for "Time zone" in its output:</p>
<div class="highlight"><pre><span></span>$ timedatectl status
<div class="highlight"><pre><span></span><code>$ timedatectl status
Local time: C  2020-01-23 12:35:50 EET
Universal time: C  2020-01-23 10:35:50 UTC
@ -110,4 +110,4 @@ there is an error. Feel free to adjust the curl options to suit your needs.</p>
</span>System clock synchronized: yes
NTP service: active
RTC in local TZ: no
</pre></div>
</code></pre></div>

+ 2
- 2
templates/docs/php.html View File

@ -1,4 +1,4 @@
<h1>PHP</h1>
<p>Below is an example of making a HTTP request to SITE_NAME from PHP.</p>
<div class="highlight"><pre><span></span><span class="x">file_get_contents(&#39;https://hc-ping.com/your-uuid-here&#39;);</span>
</pre></div>
<div class="highlight"><pre><span></span><code><span class="x">file_get_contents(&#39;https://hc-ping.com/your-uuid-here&#39;);</span>
</code></pre></div>

+ 6
- 6
templates/docs/powershell.html View File

@ -5,19 +5,19 @@
<p>Here is a simple PowerShell script that pings SITE_NAME. When scheduled to
run with Task Scheduler, it will essentially just send regular "I'm alive" messages.
You can of course extend it to do more things.</p>
<div class="highlight"><pre><span></span><span class="c1"># inside a PowerShell script:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># inside a PowerShell script:</span>
Invoke-RestMethod PING_URL
</pre></div>
</code></pre></div>
<p>Save the above to e.g. <code>C:\Scripts\healthchecks.ps1</code>.
Then use the following command in a Scheduled Task to run the script:</p>
<div class="highlight"><pre><span></span>powershell.exe -ExecutionPolicy bypass -File C:<span class="se">\S</span>cripts<span class="se">\h</span>ealthchecks.ps1
</pre></div>
<div class="highlight"><pre><span></span><code>powershell.exe -ExecutionPolicy bypass -File C:<span class="se">\S</span>cripts<span class="se">\h</span>ealthchecks.ps1
</code></pre></div>
<p>In simple cases, you can also pass the script to PowerShell directly,
using the "-command" argument:</p>
<div class="highlight"><pre><span></span><span class="c1"># Without an underlying script, passing the command to PowerShell directly:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># Without an underlying script, passing the command to PowerShell directly:</span>
powershell.exe -command <span class="p">&amp;</span><span class="o">{</span>Invoke-RestMethod PING_URL<span class="o">}</span>
</pre></div>
</code></pre></div>

+ 8
- 8
templates/docs/python.html View File

@ -1,26 +1,26 @@
<h1>Python</h1>
<p>If you are already using the requests library, it's convenient to also use it here:</p>
<div class="highlight"><pre><span></span><span class="c1"># using requests:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># using requests:</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">)</span>
</pre></div>
</code></pre></div>
<p>Otherwise, you can use the urllib standard module.</p>
<div class="highlight"><pre><span></span><span class="c1"># urllib with python 3.x:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># urllib with python 3.x:</span>
<span class="kn">import</span> <span class="nn">urllib.request</span>
<span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">)</span>
</pre></div>
</code></pre></div>
<div class="highlight"><pre><span></span><span class="c1"># urllib with python 2.x:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># urllib with python 2.x:</span>
<span class="kn">import</span> <span class="nn">urllib</span>
<span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">)</span>
</pre></div>
</code></pre></div>
<p>You can include additional diagnostic information in the in the request body (for POST requests):</p>
<div class="highlight"><pre><span></span><span class="c1"># Passing diagnostic information in the POST body:</span>
<div class="highlight"><pre><span></span><code><span class="c1"># Passing diagnostic information in the POST body:</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;PING_URL&quot;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s2">&quot;temperature=-7&quot;</span><span class="p">)</span>
</pre></div>
</code></pre></div>

+ 2
- 2
templates/docs/ruby.html View File

@ -1,7 +1,7 @@
<h1>Ruby</h1>
<p>Below is an example of making a HTTP request to SITE_NAME from Ruby.</p>
<div class="highlight"><pre><span></span><span class="nb">require</span> <span class="s1">&#39;net/http&#39;</span>
<div class="highlight"><pre><span></span><code><span class="nb">require</span> <span class="s1">&#39;net/http&#39;</span>
<span class="nb">require</span> <span class="s1">&#39;uri&#39;</span>
<span class="no">Net</span><span class="o">::</span><span class="no">HTTP</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="no">URI</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s1">&#39;PING_URL&#39;</span><span class="p">))</span>
</pre></div>
</code></pre></div>

+ 6
- 6
templates/docs/signalling_failures.html View File

@ -6,7 +6,7 @@ to you getting a notification.</p>
<h2>Shell Scripts</h2>
<p>The below shell script sends either a "success" or "failure" ping depending on
command's (certbot in this example) exit code:</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<div class="highlight"><pre><span></span><code><span class="ch">#!/bin/sh</span>
<span class="nv">url</span><span class="o">=</span>PING_URL
@ -14,26 +14,26 @@ command's (certbot in this example) exit code:</p>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> -ne <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span> <span class="nv">url</span><span class="o">=</span><span class="nv">$url</span>/fail<span class="p">;</span> <span class="k">fi</span>
curl --retry <span class="m">3</span> <span class="nv">$url</span>
</pre></div>
</code></pre></div>
<h2>Python</h2>
<p>Below is a skeleton code example in Python which signals a failure when the
work function returns an unexpected value or throws an exception:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
<span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;PING_URL&quot;</span>
<span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
<span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
<span class="c1"># Return a truthy value on success.</span>
<span class="c1"># Return a falsy value or throw an exception on failure.</span>
<span class="k">return</span> <span class="bp">True</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">success</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">success</span> <span class="o">=</span> <span class="n">do_work</span><span class="p">()</span>
<span class="k">finally</span><span class="p">:</span>
<span class="c1"># On success, requests PING_URL</span>
<span class="c1"># On failure, requests PING_URL/fail</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">URL</span> <span class="k">if</span> <span class="n">success</span> <span class="k">else</span> <span class="n">URL</span> <span class="o">+</span> <span class="s2">&quot;/fail&quot;</span><span class="p">)</span>
</pre></div>
</code></pre></div>

Loading…
Cancel
Save