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.

57 lines
1.4 KiB

  1. # Signalling failures
  2. You can actively signal a failure to SITE_NAME by slightly changing the
  3. ping URL: append either `/fail` or `/{exit-status}` to your normal ping URL.
  4. The exit status should be a 0-255 integer. SITE_NAME will interpret
  5. exit status 0 as success, and all non-zero values as failures.
  6. Examples:
  7. ```bash
  8. # Reports failure by appending the /fail suffix:
  9. curl --retry 3 PING_URL/fail
  10. # Reports failure by appending a non-zero exit status:
  11. curl --retry 3 PING_URL/1
  12. ```
  13. By actively signalling failures to SITE_NAME, you can minimize the delay from your
  14. monitored service encountering a problem to you getting notified about it.
  15. ## Shell Scripts
  16. The below shell script appends `$?` (a special variable which contains the
  17. exit status of the last executed command) to the ping URL:
  18. ```bash
  19. #!/bin/sh
  20. /usr/bin/certbot renew
  21. curl --retry 3 PING_URL/$?
  22. ```
  23. ## Python
  24. Below is a skeleton code example in Python which signals a failure when the
  25. work function returns an unexpected value or throws an exception:
  26. ```python
  27. import requests
  28. URL = "PING_URL"
  29. def do_work():
  30. # Do your number crunching, backup dumping, newsletter sending work here.
  31. # Return a truthy value on success.
  32. # Return a falsy value or throw an exception on failure.
  33. return True
  34. success = False
  35. try:
  36. success = do_work()
  37. finally:
  38. # On success, requests PING_URL
  39. # On failure, requests PING_URL/fail
  40. requests.get(URL if success else URL + "/fail")
  41. ```