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.

24 lines
1.8 KiB

  1. <h1>Signalling failures</h1>
  2. <p>Append <code>/fail</code> to a ping URL and use it to actively signal a failure.
  3. Requesting the <code>/fail</code> URL will immediately mark the check as "down".
  4. You can use this feature to minimize the delay from your monitored service failing
  5. to you getting a notification.</p>
  6. <h2>Python</h2>
  7. <p>Below is a skeleton code example in Python which signals a failure when the
  8. work function returns an unexpected value or throws an exception:</p>
  9. <div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
  10. <span class="n">URL</span> <span class="o">=</span> <span class="s2">&quot;PING_URL&quot;</span>
  11. <span class="k">def</span> <span class="nf">do_work</span><span class="p">():</span>
  12. <span class="c1"># Do your number crunching, backup dumping, newsletter sending work here.</span>
  13. <span class="c1"># Return a truthy value on success.</span>
  14. <span class="c1"># Return a falsy value or throw an exception on failure.</span>
  15. <span class="k">return</span> <span class="bp">True</span>
  16. <span class="n">success</span> <span class="o">=</span> <span class="bp">False</span>
  17. <span class="k">try</span><span class="p">:</span>
  18. <span class="n">success</span> <span class="o">=</span> <span class="n">do_work</span><span class="p">()</span>
  19. <span class="k">finally</span><span class="p">:</span>
  20. <span class="c1"># On success, requests PING_URL</span>
  21. <span class="c1"># On failure, requests PING_URL/fail</span>
  22. <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>
  23. </pre></div>