You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

25 lines
1.8 KiB

<h1>Signalling failures</h1>
<p>Append <code>/fail</code> to a ping URL and use it to actively signal a failure.
Requesting the <code>/fail</code> URL will immediately mark the check as "down".
You can use this feature to minimize the delay from your monitored service failing
to you getting a notification.</p>
<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>
<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="n">success</span> <span class="o">=</span> <span class="bp">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>