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.

33 lines
2.8 KiB

  1. <h1>Attaching Logs</h1>
  2. <p>SITE_NAME ping endpoints accept HTTP HEAD, GET and POST request methods.</p>
  3. <p>When using HTTP POST, <strong>you can include arbitrary payload in the request body</strong>.
  4. If the request body looks like a UTF-8 string, SITE_NAME will log the first 10 kilobytes of
  5. the request body, so you can inspect it later.</p>
  6. <h2>Logging Command Output</h2>
  7. <p>In this example, we run <code>certbot renew</code>, capture its output, and submit
  8. the captured output to SITE_NAME:</p>
  9. <div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
  10. <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>
  11. 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
  12. </pre></div>
  13. <h2>In Combination with the <code>/fail</code> Endpoint</h2>
  14. <p>We can extend the previous example and signal either success or failure
  15. depending on the exit code:</p>
  16. <div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
  17. <span class="nv">url</span><span class="o">=</span>PING_URL
  18. <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>
  19. <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>
  20. 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>
  21. </pre></div>
  22. <h2>All in One Line</h2>
  23. <p>Finally, all of the above can be packaged in a single line. The one-line
  24. version can be put directly in crontab, without using a wrapper script.</p>
  25. <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>
  26. </pre></div>