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.

51 lines
1.4 KiB

  1. # Shell Scripts
  2. You can easily add SITE_NAME monitoring to a shell script. All you
  3. have to do is make a HTTP request at the end of the script.
  4. [curl](https://curl.haxx.se/docs/manpage.html) and
  5. [wget](https://www.gnu.org/software/wget/manual/wget.html)
  6. are two common command line HTTP clients you can use.
  7. ```bash
  8. # Sending a HTTP GET request with curl:
  9. curl --retry 3 PING_URL
  10. # Silent version (no stdout/stderr output unless curl hits an error):
  11. curl -fsS --retry 3 PING_URL
  12. # Sending a HTTP GET request with wget:
  13. wget PING_URL -O /dev/null
  14. ```
  15. ## Signalling Failure from Shell Scripts
  16. You can append `/fail` to any ping URL and use the resulting URL to actively
  17. signal a failure. The below example:
  18. * runs `/usr/bin/certbot renew`
  19. * if the certbot command is successful (exit code 0), send HTTP GET to `PING_URL`
  20. * otherwise, send HTTP GET to `PING_URL/fail`
  21. ```bash
  22. #!/bin/sh
  23. # Payload here:
  24. /usr/bin/certbot renew
  25. # Ping SITE_NAME
  26. curl --retry 3 "PING_URL$([ $? -ne 0 ] && echo -n /fail)"
  27. ```
  28. ## Logging Command Output
  29. When pinging with HTTP POST, you can put extra diagnostic information in request
  30. body. If the request body looks like a valid UTF-8 string, SITE_NAME
  31. will accept and store first 10KB of the request body.
  32. In the below example, certbot's output is captured and submitted via HTTP POST:
  33. ```bash
  34. #!/bin/sh
  35. m=$(/usr/bin/certbot renew 2>&1)
  36. curl -fsS --retry 3 -X POST --data-raw "$m" PING_URL
  37. ```