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.

46 lines
1.1 KiB

  1. # Signalling failures
  2. Append `/fail` to a ping URL and use it to actively signal a failure.
  3. Requesting the `/fail` 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.
  6. ## Shell Scripts
  7. The below shell script sends sends either a "success" or "failure" ping depending on
  8. command's (certbot in this example) exit code:
  9. ```bash
  10. #!/bin/sh
  11. url=PING_URL
  12. /usr/bin/certbot renew
  13. if [ $? -ne 0 ]; then url=$url/fail; fi
  14. curl --retry 3 $url
  15. ```
  16. ## Python
  17. Below is a skeleton code example in Python which signals a failure when the
  18. work function returns an unexpected value or throws an exception:
  19. ```python
  20. import requests
  21. URL = "PING_URL"
  22. def do_work():
  23. # Do your number crunching, backup dumping, newsletter sending work here.
  24. # Return a truthy value on success.
  25. # Return a falsy value or throw an exception on failure.
  26. return True
  27. success = False
  28. try:
  29. success = do_work()
  30. finally:
  31. # On success, requests PING_URL
  32. # On failure, requests PING_URL/fail
  33. requests.get(URL if success else URL + "/fail")
  34. ```