Browse Source

Update pinging examples.

pull/405/head
Pēteris Caune 4 years ago
parent
commit
028e131327
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
13 changed files with 47 additions and 26 deletions
  1. +7
    -3
      templates/docs/python.html
  2. +6
    -2
      templates/docs/python.md
  3. +2
    -3
      templates/front/snippets/bash_curl.html
  4. +2
    -3
      templates/front/snippets/bash_curl.txt
  5. +2
    -2
      templates/front/snippets/bash_wget.html
  6. +2
    -2
      templates/front/snippets/bash_wget.txt
  7. +1
    -1
      templates/front/snippets/browser.html
  8. +1
    -1
      templates/front/snippets/browser.txt
  9. +1
    -1
      templates/front/snippets/crontab.html
  10. +1
    -1
      templates/front/snippets/crontab.txt
  11. +6
    -1
      templates/front/snippets/python_requests.html
  12. +6
    -1
      templates/front/snippets/python_requests.txt
  13. +10
    -5
      templates/front/welcome.html

+ 7
- 3
templates/docs/python.html View File

@ -1,8 +1,12 @@
<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><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>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">requests</span>
<span class="k">try</span><span class="p">:</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> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">RequestException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="c1"># Log ping failure here...</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Ping failed: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
</code></pre></div>


+ 6
- 2
templates/docs/python.md View File

@ -3,9 +3,13 @@
If you are already using the requests library, it's convenient to also use it here:
```python
# using requests:
import requests
requests.get("PING_URL")
try:
requests.get("PING_URL", timeout=10)
except requests.RequestException as e:
# Log ping failure here...
print("Ping failed: %s" % e)
```
Otherwise, you can use the urllib standard module.


+ 2
- 3
templates/front/snippets/bash_curl.html View File

@ -1,4 +1,3 @@
<div class="highlight"><pre><span></span><span class="c1"># using curl:</span>
<span class="c1"># (make sure it is installed on your system!)</span>
curl --retry <span class="m">3</span> {{ ping_url }}
<div class="highlight"><pre><span></span><span class="c1"># using curl (10 second timeout, retry up to 5 times):</span>
curl -m <span class="m">10</span> --retry <span class="m">5</span> {{ ping_url }}
</pre></div>

+ 2
- 3
templates/front/snippets/bash_curl.txt View File

@ -1,3 +1,2 @@
# using curl:
# (make sure it is installed on your system!)
curl --retry 3 PING_URL
# using curl (10 second timeout, retry up to 5 times):
curl -m 10 --retry 5 PING_URL

+ 2
- 2
templates/front/snippets/bash_wget.html View File

@ -1,3 +1,3 @@
<div class="highlight"><pre><span></span><span class="c1"># using wget:</span>
wget {{ ping_url }} -O /dev/null
<div class="highlight"><pre><span></span><span class="c1"># using wget (10 second timeout, retry up to 5 times):</span>
wget {{ ping_url }} -T <span class="m">10</span> -t <span class="m">5</span> -O /dev/null
</pre></div>

+ 2
- 2
templates/front/snippets/bash_wget.txt View File

@ -1,2 +1,2 @@
# using wget:
wget PING_URL -O /dev/null
# using wget (10 second timeout, retry up to 5 times):
wget PING_URL -T 10 -t 5 -O /dev/null

+ 1
- 1
templates/front/snippets/browser.html View File

@ -1,4 +1,4 @@
<div class="highlight"><pre><span></span><span class="c1">// the server returns appropriate CORS headers so cross-domain AJAX requests should work:</span>
<div class="highlight"><pre><span></span><span class="c1">// the server returns appropriate CORS headers so cross-domain AJAX requests work:</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>
<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>


+ 1
- 1
templates/front/snippets/browser.txt View File

@ -1,4 +1,4 @@
// the server returns appropriate CORS headers so cross-domain AJAX requests should work:
// the server returns appropriate CORS headers so cross-domain AJAX requests work:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'PING_URL', true);
xhr.send(null);

+ 1
- 1
templates/front/snippets/crontab.html View File

@ -1,3 +1,3 @@
<div class="highlight"><pre><span></span><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 }}
<span class="m">8</span> <span class="m">6</span> * * * /home/user/backup.sh <span class="o">&amp;&amp;</span> curl -fsS -m <span class="m">10</span> --retry <span class="m">5</span> -o /dev/null {{ ping_url }}
</pre></div>

+ 1
- 1
templates/front/snippets/crontab.txt View File

@ -1,2 +1,2 @@
# m h dom mon dow command
8 6 * * * /home/user/backup.sh && curl -fsS --retry 3 -o /dev/null PING_URL
8 6 * * * /home/user/backup.sh && curl -fsS -m 10 --retry 5 -o /dev/null PING_URL

+ 6
- 1
templates/front/snippets/python_requests.html View File

@ -1,4 +1,9 @@
<div class="highlight"><pre><span></span><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>
<span class="k">try</span><span class="p">:</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> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">RequestException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="c1"># Log ping failure here...</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Ping failed: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
</pre></div>

+ 6
- 1
templates/front/snippets/python_requests.txt View File

@ -1,3 +1,8 @@
# using requests:
import requests
requests.get("PING_URL")
try:
requests.get("PING_URL", timeout=10)
except requests.RequestException as e:
# Log ping failure here...
print("Ping failed: %s" % e)

+ 10
- 5
templates/front/welcome.html View File

@ -37,7 +37,7 @@
<div class="col-sm-6 col-sm-pull-6">
<h2 id="pitch-subtitle">
For each of your periodic tasks,
{% site_name %} provides an unique URL like this one:
{% site_name %} provides an unique URL similar to this one:
</h2>
<div id="pitch-url">
<code>{{ ping_url }}</code>
@ -118,10 +118,15 @@
</div>
<div class="tab-pane tab-pane-email" id="email">
<p>
As an alternative to HTTP and HTTPS requests,
you can "ping" this check by sending an
email message to
<a href="mailto:{{ check.email }}">{{ check.email }}</a>
As an alternative to HTTP requests,
you can also report "liveness" by
<strong>sending email messages</strong>.
</p>
<p>
You can instruct {% site_name %} to look for a particular
keyword in the subject line. This is handy when your backup
software sends an email after every run, and uses a different
subject line depending on success or failure.
</p>
</div>
</div>


Loading…
Cancel
Save