monitoring: badge backgrounds for ok/info/warn/error

This commit is contained in:
Hernâni Marques 2026-07-17 15:48:56 +02:00
parent 3d4e883cdb
commit f8affeb651
No known key found for this signature in database
GPG key ID: CB5738652768F7E9

View file

@ -352,19 +352,28 @@ koopa_ssh_python() {
with_timeout "$t" ssh "${SSH_BASE_OPTS[@]}" "${KOOPA_SSH}" python3 -
}
# ANSI colours — tag + body (label bold, detail dim). Off: NO_COLOR=1 or CLICOLOR=0.
# ANSI colours — badge tags (fg+bg) + body (label bold, detail dim).
# Off: NO_COLOR=1 or CLICOLOR=0. Badges need a terminal that supports SGR bg.
if [ "${NO_COLOR:-0}" = "1" ] || [ "${CLICOLOR:-1}" = "0" ]; then
G= R= Y= C= M= D= W= B= N=
BG_OK= BG_INFO= BG_WARN= BG_ERR= BG_BLK= BG_SEC=
else
G=$'\e[1;32m' # bold green [OK]
R=$'\e[1;31m' # bold red [ERROR]
Y=$'\e[1;33m' # bold yellow [WARN]
C=$'\e[1;36m' # bold cyan [INFO]
M=$'\e[1;35m' # bold magenta [BLOCKER]
D=$'\e[2m' # dim tid / detail / sep
W=$'\e[1;37m' # bold white main label text
B=$'\e[1m' # bold section headers
N=$'\e[0m' # reset
G=$'\e[1;32m' # green text (totals)
R=$'\e[1;31m' # red text
Y=$'\e[1;33m' # yellow text
C=$'\e[1;36m' # cyan text
M=$'\e[1;35m' # magenta text
D=$'\e[2m' # dim tid / detail
W=$'\e[1;37m' # bold white label
B=$'\e[1m' # bold section
N=$'\e[0m' # reset
# Badge: bright text on solid background (space-padded in _msg_line)
BG_OK=$'\e[1;30;42m' # black on green
BG_INFO=$'\e[1;30;46m' # black on cyan
BG_WARN=$'\e[1;30;43m' # black on yellow
BG_ERR=$'\e[1;37;41m' # white on red
BG_BLK=$'\e[1;37;45m' # white on magenta
BG_SEC=$'\e[1;37;44m' # white on blue (section)
fi
PASS_N=0
@ -401,18 +410,18 @@ _fmt_tid() {
fi
}
# One concrete line: [TAG] tid label · detail
# $1=tag colour $2=tag text $3=label colour $4=label $5=detail (optional)
# $1=badge style (bg+fg) $2=tag text $3=label colour $4=label $5=detail
_msg_line() {
local tcol="$1" tag="$2" lcol="$3" label="$4" detail="${5:-}"
# Fixed-width tag column: "[OK] " / "[BLOCKER]" (8 chars inside incl. brackets)
local badge="$1" tag="$2" lcol="$3" label="$4" detail="${5:-}"
# Fixed-width badge cell: " OK " / " BLOCKER" (9 chars, space-padded)
local tcell
tcell=$(printf '%-9s' "[${tag}]")
tcell=$(printf ' %-7s ' "$tag")
if [ -n "$detail" ]; then
printf '%s%s%s %s%s%s%s %s·%s %s%s%s\n' \
"$tcol" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N" "$D" "$N" "$D" "$detail" "$N"
"$badge" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N" "$D" "$N" "$D" "$detail" "$N"
else
printf '%s%s%s %s%s%s%s\n' \
"$tcol" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N"
"$badge" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N"
fi
}
@ -420,14 +429,14 @@ ok() {
# ok "what is good" ["concrete evidence: HTTP 200 · 12ms · …"]
local label="$1" detail="${2:-}"
_take_tid
_msg_line "$G" "OK" "$W" "$label" "$detail"
_msg_line "$BG_OK" "OK" "$W" "$label" "$detail"
PASS_N=$((PASS_N + 1))
}
# component-scoped error: err bank "what failed" "why / HTTP / path"
err() {
local comp="$1" msg="$2" detail="${3:-}"
_take_tid
_msg_line "$R" "ERROR" "$W" "${comp}: ${msg}" "$detail"
_msg_line "$BG_ERR" "ERROR" "$W" "${comp}: ${msg}" "$detail"
FAIL_N=$((FAIL_N + 1))
ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ · $detail}")
}
@ -435,7 +444,7 @@ err() {
fail() {
local label="$1" detail="${2:-}"
_take_tid
_msg_line "$R" "ERROR" "$W" "$label" "$detail"
_msg_line "$BG_ERR" "ERROR" "$W" "$label" "$detail"
FAIL_N=$((FAIL_N + 1))
ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ · $detail}")
}
@ -455,40 +464,42 @@ warn() {
head="$a1"
detail=""
fi
_msg_line "$Y" "WARN" "$W" "$head" "$detail"
_msg_line "$BG_WARN" "WARN" "$W" "$head" "$detail"
WARN_N=$((WARN_N + 1))
}
info() {
# info "topic" ["concrete fact / value / next step"]
local label="$1" detail="${2:-}"
_take_tid
_msg_line "$C" "INFO" "$W" "$label" "$detail"
_msg_line "$BG_INFO" "INFO" "$W" "$label" "$detail"
INFO_N=$((INFO_N + 1))
}
blocker() {
# Hard stop on pay/withdraw path: blocker "step" "why it cannot continue"
local step="$1" msg="$2"
_take_tid
_msg_line "$M" "BLOCKER" "$W" "${step}" "$msg"
_msg_line "$BG_BLK" "BLOCKER" "$W" "${step}" "$msg"
BLOCKERS+=("${LAST_TID:+$LAST_TID }[$step] $msg")
FAIL_N=$((FAIL_N + 1))
ERRORS+=("BLOCKER ${LAST_TID:+$LAST_TID }[$step] $msg")
}
section() {
printf '\n%s==%s %s%s%s %s==%s\n' "$D" "$N" "$B" "$*" "$N" "$D" "$N"
# Blue badge + bold title
local title=" $* "
printf '\n%s%s%s %s%s%s\n' "$BG_SEC" " == " "$N" "$B" "$title" "$N"
}
summary() {
echo ""
if [ "${#BLOCKERS[@]}" -gt 0 ]; then
printf '%s--- BLOCKERS%s %s(pay/withdraw cannot finish)%s %s---%s\n' "$M" "$N" "$D" "$N" "$M" "$N"
printf '%s BLOCKERS %s %s(pay/withdraw cannot finish)%s\n' "$BG_BLK" "$N" "$D" "$N"
local b
for b in "${BLOCKERS[@]}"; do
printf '%s •%s %s%s%s\n' "$M" "$N" "$W" "$b" "$N"
done
fi
if [ "${#ERRORS[@]}" -gt 0 ] && [ "${#BLOCKERS[@]}" -lt "${#ERRORS[@]}" ]; then
printf '%s--- ERRORS%s %s(failed checks)%s %s---%s\n' "$R" "$N" "$D" "$N" "$R" "$N"
printf '%s ERRORS %s %s(failed checks)%s\n' "$BG_ERR" "$N" "$D" "$N"
local e
for e in "${ERRORS[@]}"; do
case "$e" in BLOCKER*) continue ;; esac