Last active
April 3, 2021 18:42
-
-
Save dimo414/d84a59ef11c642f7c0b6cc2f7e2f250b to your computer and use it in GitHub Desktop.
Healthchecks.io + blink(1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Queries the given Healthchecks.io project/tags, and sets a blink(1) | |
# based on the results. | |
# | |
# Suggest running once per minute via cron. | |
URL_F='https://healthchecks.io/badge/%s.json' | |
all_counts=() | |
blink() { | |
/usr/local/bin/blink1-tool -q "$@" | |
} | |
query_healthcheck() { | |
local url=$(printf "$URL_F" "${1:?}") counts i=0 arg count | |
readarray -t counts < <(curl -fsS --retry 3 "$url" | jq '.down, .grace, .total') | |
for arg in "${counts[@]}"; do | |
all_counts[i++]=$(( arg + ${all_counts[i]:-0} )) | |
done | |
} | |
for project; do | |
query_healthcheck "$project" | |
done | |
if (( ${#all_counts[@]} != 3 )); then | |
blink --magenta --blink 15 | |
elif (( ${all_counts[0]} > 0 )); then # down | |
blink --red | |
elif (( ${all_counts[1]} > 0 )); then # grace | |
blink --rgb=255,175,0 | |
else | |
blink --rgb=0,100,0 --blink "${all_counts[2]}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment