34 lines
1.5 KiB
Text
34 lines
1.5 KiB
Text
|
|
# One result PER UNIT, not one for the host. A host running four services
|
||
|
|
# needs four endpoints: a single red light would tell you "something on vipy
|
||
|
|
# is down" without saying which, and that is the question you actually have.
|
||
|
|
#
|
||
|
|
# Keys are host-qualified because unit names collide - caddy runs on four
|
||
|
|
# machines. Gatus builds the key as sanitize(group)_sanitize(name), so
|
||
|
|
# group "services" + name "vipy/caddy" becomes services_vipy-caddy.
|
||
|
|
local prefix="{{ healthcheck_units_key_prefix }}"
|
||
|
|
local down=""
|
||
|
|
|
||
|
|
for unit in {{ healthcheck_units | join(' ') }}; do
|
||
|
|
local state substate
|
||
|
|
state=$(systemctl is-active "$unit" 2>/dev/null || true)
|
||
|
|
substate=$(systemctl show -p SubState --value "$unit" 2>/dev/null || true)
|
||
|
|
|
||
|
|
if [ "$state" = "active" ]; then
|
||
|
|
report_key "${prefix}-${unit}" "true" "${unit} active (${substate:-running})"
|
||
|
|
else
|
||
|
|
# `failed` and `inactive` are different stories: one crashed, one was
|
||
|
|
# stopped. Both are down, but the message should say which.
|
||
|
|
local detail="${unit} is ${state:-unknown}"
|
||
|
|
[ "$state" = "failed" ] && detail="${detail} (${substate:-failed})"
|
||
|
|
report_key "${prefix}-${unit}" "false" "$detail"
|
||
|
|
down="${down}${down:+, }${unit}=${state:-unknown}"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
if [ -n "$down" ]; then
|
||
|
|
MESSAGE="down: ${down}"
|
||
|
|
return 1
|
||
|
|
fi
|
||
|
|
MESSAGE="all {{ healthcheck_units | length }} units active"
|
||
|
|
return 0
|