Skip to content

Commit 6f4257e

Browse files
authored
info-healthchecks.io: add script
1 parent 28fc405 commit 6f4257e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Script: info-healthchecks.io
2+
3+
Shows the health of your services registered with [healthchecks.io](https://healthchecks.io).
4+
5+
![screenshot](screenshots/info-healthchecks.io.png)
6+
7+
8+
## Dependencies
9+
10+
* `jq`
11+
* `curl`
12+
13+
## Configuration
14+
15+
Modify any of the all-caps variables to configure the script:
16+
* `API_KEY`: Your [healthchecks.io](https://healthchecks.io) API key. These are project specific and can be generated on the project settings page.
17+
* `CHECK_ENDPOINT`: URL of the checks API endpoint. Change if self-hosting.
18+
* `STATES`: Array of states to monitor. Available options: `"up" "down" "new" "pending" "grace" "started" "paused"`
19+
* `COLORS`: Associative array that maps a color to each configured state. Defaults to white (#ffffff).
20+
* `SHOWN_TAGS`: Array of tags to show. Leave empty to disable filtering based on tags.
21+
22+
## Module
23+
24+
```ini
25+
[module/info-healthchecks.io]
26+
type = custom/script
27+
exec = ~/polybar-scripts/info-healthchecks.io.sh
28+
interval = 30
29+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Your API Key
4+
API_KEY=""
5+
# URL of the checks api endpoint. Change if self-hosting the service.
6+
CHECK_ENDPOINT="https://healthchecks.io/api/v1/checks/"
7+
8+
# States to track
9+
# Available options: up down new pending grace started paused
10+
STATES=("up" "down")
11+
# Color of each state. Defaults to white (#ffffff).
12+
declare -A COLORS=( [up]="#7cfc00" [down]="#ff0000" )
13+
# Leave empty to show all tags
14+
SHOWN_TAGS=()
15+
16+
function build_url {
17+
url=$CHECK_ENDPOINT
18+
next_sep="?"
19+
for tag in "${SHOWN_TAGS[@]}"; do
20+
url+="${next_sep}tag=${tag}"
21+
next_sep="&"
22+
done
23+
echo "$url"
24+
}
25+
26+
response=$(curl --silent --header "X-Api-Key: ${API_KEY}" "$(build_url)")
27+
28+
declare -A stati
29+
30+
for status in "up" "down"; do
31+
stati[$status]=0
32+
done
33+
34+
for status in $(echo "$response" | jq -r '.checks[].status'); do
35+
stati[$status]=$((stati[$status] + 1))
36+
done
37+
38+
output=""
39+
for status in "${STATES[@]}"; do
40+
count=${stati[$status]}
41+
if [ ${COLORS[$status]+_} ]; then
42+
color=${COLORS[$status]}
43+
else
44+
color="#ffffff"
45+
fi
46+
output+="|%{F${color}}${count}%{F-}"
47+
done
48+
49+
echo ${output:1}
576 Bytes
Loading

0 commit comments

Comments
 (0)