From kromonos, 7 Months ago, written in Bash.
Embed
  1. #!/bin/bash
  2. API_KEY=your-api-key-here
  3. TIMEOUT=10
  4. GRACE=60
  5.  
  6. PAYLOAD='{"name": "'${1}'", "timeout": '${TIMEOUT}', "grace": '${GRACE}', "unique": ["name"]}'
  7. URL=$(curl -s https://health.error.cf/api/v1/checks/  -H "X-Api-Key: ${API_KEY}" -d "${PAYLOAD}"  | jq -r .ping_url)
  8.  
  9. curl --retry 3 ${URL}/start > /dev/null 2>&1
  10.  
  11. RETURN=$(curl -o /dev/null -Isw '%{http_code}\n' ${1})
  12. if [[ ${RETURN} =~ ^[2-4]0[0-4]$ ]]; then
  13.     curl --retry 3 ${URL} > /dev/null 2>&1
  14. else
  15.     curl --retry 3 -X POST --data-raw "Check ${1} returned with ${RETURN}" ${URL}/fail > /dev/null 2>&1
  16. fi