Browse Source

Markdown with Pygments 2.4 and later wraps code in <code> tags (https://github.com/Python-Markdown/markdown/pull/862).

Reset CSS for code tags inside pre blocks.
pull/340/head
Pēteris Caune 5 years ago
parent
commit
3092eaf88d
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
13 changed files with 78 additions and 70 deletions
  1. +9
    -1
      static/css/docs.css
  2. +6
    -6
      templates/docs/attaching_logs.html
  3. +6
    -6
      templates/docs/bash.html
  4. +2
    -2
      templates/docs/csharp.html
  5. +18
    -18
      templates/docs/http_api.html
  6. +4
    -4
      templates/docs/javascript.html
  7. +3
    -3
      templates/docs/measuring_script_run_time.html
  8. +6
    -6
      templates/docs/monitoring_cron_jobs.html
  9. +2
    -2
      templates/docs/php.html
  10. +6
    -6
      templates/docs/powershell.html
  11. +8
    -8
      templates/docs/python.html
  12. +2
    -2
      templates/docs/ruby.html
  13. +6
    -6
      templates/docs/signalling_failures.html

+ 9
- 1
static/css/docs.css View File

@ -83,6 +83,14 @@ a.section:hover {
border-radius: 4px;
}
.page-docs pre code {
padding: 0;
font-size: 13px;
background-color: transparent;
border-radius: 0;
}
.docs-content, .docs-content .table td {
line-height: 1.8;
}
@ -115,4 +123,4 @@ a.section:hover {
.docs-content img {
max-width: 100%;
}
}
}

+ 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> -X POST --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> -X POST --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 -X POST --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 -X POST --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>

+ 6
- 6
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,8 +37,8 @@ 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> -X POST --data-raw <span class="s2">&quot;</span><span class="nv">$m</span><span class="s2">&quot;</span> PING_URL
</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> PING_URL &gt; /dev/null
</pre></div>
</code></pre></div>
<p>Now, each time your cron job runs, it will send a HTTP request to the ping URL.
@ -100,7 +100,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
@ -109,4 +109,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 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