mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-23 16:07:39 +00:00
11 lines
1.1 KiB
HTML
11 lines
1.1 KiB
HTML
<div class="highlight"><pre><span></span><span class="c1"># Using Python 3 standard library:</span>
|
|
<span class="kn">import</span> <span class="nn">socket</span>
|
|
<span class="kn">import</span> <span class="nn">urllib.request</span>
|
|
|
|
<span class="k">try</span><span class="p">:</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">"{{ ping_url }}"</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">socket</span><span class="o">.</span><span class="n">error</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">"Ping failed: </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
|
|
</pre></div>
|