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 - 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 if [ "${NO_COLOR:-0}" = "1" ] || [ "${CLICOLOR:-1}" = "0" ]; then
G= R= Y= C= M= D= W= B= N= G= R= Y= C= M= D= W= B= N=
BG_OK= BG_INFO= BG_WARN= BG_ERR= BG_BLK= BG_SEC=
else else
G=$'\e[1;32m' # bold green [OK] G=$'\e[1;32m' # green text (totals)
R=$'\e[1;31m' # bold red [ERROR] R=$'\e[1;31m' # red text
Y=$'\e[1;33m' # bold yellow [WARN] Y=$'\e[1;33m' # yellow text
C=$'\e[1;36m' # bold cyan [INFO] C=$'\e[1;36m' # cyan text
M=$'\e[1;35m' # bold magenta [BLOCKER] M=$'\e[1;35m' # magenta text
D=$'\e[2m' # dim tid / detail / sep D=$'\e[2m' # dim tid / detail
W=$'\e[1;37m' # bold white main label text W=$'\e[1;37m' # bold white label
B=$'\e[1m' # bold section headers B=$'\e[1m' # bold section
N=$'\e[0m' # reset 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 fi
PASS_N=0 PASS_N=0
@ -401,18 +410,18 @@ _fmt_tid() {
fi fi
} }
# One concrete line: [TAG] tid label · detail # 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() { _msg_line() {
local tcol="$1" tag="$2" lcol="$3" label="$4" detail="${5:-}" local badge="$1" tag="$2" lcol="$3" label="$4" detail="${5:-}"
# Fixed-width tag column: "[OK] " / "[BLOCKER]" (8 chars inside incl. brackets) # Fixed-width badge cell: " OK " / " BLOCKER" (9 chars, space-padded)
local tcell local tcell
tcell=$(printf '%-9s' "[${tag}]") tcell=$(printf ' %-7s ' "$tag")
if [ -n "$detail" ]; then if [ -n "$detail" ]; then
printf '%s%s%s %s%s%s%s %s·%s %s%s%s\n' \ 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 else
printf '%s%s%s %s%s%s%s\n' \ 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 fi
} }
@ -420,14 +429,14 @@ ok() {
# ok "what is good" ["concrete evidence: HTTP 200 · 12ms · …"] # ok "what is good" ["concrete evidence: HTTP 200 · 12ms · …"]
local label="$1" detail="${2:-}" local label="$1" detail="${2:-}"
_take_tid _take_tid
_msg_line "$G" "OK" "$W" "$label" "$detail" _msg_line "$BG_OK" "OK" "$W" "$label" "$detail"
PASS_N=$((PASS_N + 1)) PASS_N=$((PASS_N + 1))
} }
# component-scoped error: err bank "what failed" "why / HTTP / path" # component-scoped error: err bank "what failed" "why / HTTP / path"
err() { err() {
local comp="$1" msg="$2" detail="${3:-}" local comp="$1" msg="$2" detail="${3:-}"
_take_tid _take_tid
_msg_line "$R" "ERROR" "$W" "${comp}: ${msg}" "$detail" _msg_line "$BG_ERR" "ERROR" "$W" "${comp}: ${msg}" "$detail"
FAIL_N=$((FAIL_N + 1)) FAIL_N=$((FAIL_N + 1))
ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ · $detail}") ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ · $detail}")
} }
@ -435,7 +444,7 @@ err() {
fail() { fail() {
local label="$1" detail="${2:-}" local label="$1" detail="${2:-}"
_take_tid _take_tid
_msg_line "$R" "ERROR" "$W" "$label" "$detail" _msg_line "$BG_ERR" "ERROR" "$W" "$label" "$detail"
FAIL_N=$((FAIL_N + 1)) FAIL_N=$((FAIL_N + 1))
ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ · $detail}") ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ · $detail}")
} }
@ -455,40 +464,42 @@ warn() {
head="$a1" head="$a1"
detail="" detail=""
fi fi
_msg_line "$Y" "WARN" "$W" "$head" "$detail" _msg_line "$BG_WARN" "WARN" "$W" "$head" "$detail"
WARN_N=$((WARN_N + 1)) WARN_N=$((WARN_N + 1))
} }
info() { info() {
# info "topic" ["concrete fact / value / next step"] # info "topic" ["concrete fact / value / next step"]
local label="$1" detail="${2:-}" local label="$1" detail="${2:-}"
_take_tid _take_tid
_msg_line "$C" "INFO" "$W" "$label" "$detail" _msg_line "$BG_INFO" "INFO" "$W" "$label" "$detail"
INFO_N=$((INFO_N + 1)) INFO_N=$((INFO_N + 1))
} }
blocker() { blocker() {
# Hard stop on pay/withdraw path: blocker "step" "why it cannot continue" # Hard stop on pay/withdraw path: blocker "step" "why it cannot continue"
local step="$1" msg="$2" local step="$1" msg="$2"
_take_tid _take_tid
_msg_line "$M" "BLOCKER" "$W" "${step}" "$msg" _msg_line "$BG_BLK" "BLOCKER" "$W" "${step}" "$msg"
BLOCKERS+=("${LAST_TID:+$LAST_TID }[$step] $msg") BLOCKERS+=("${LAST_TID:+$LAST_TID }[$step] $msg")
FAIL_N=$((FAIL_N + 1)) FAIL_N=$((FAIL_N + 1))
ERRORS+=("BLOCKER ${LAST_TID:+$LAST_TID }[$step] $msg") ERRORS+=("BLOCKER ${LAST_TID:+$LAST_TID }[$step] $msg")
} }
section() { 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() { summary() {
echo "" echo ""
if [ "${#BLOCKERS[@]}" -gt 0 ]; then 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 local b
for b in "${BLOCKERS[@]}"; do for b in "${BLOCKERS[@]}"; do
printf '%s •%s %s%s%s\n' "$M" "$N" "$W" "$b" "$N" printf '%s •%s %s%s%s\n' "$M" "$N" "$W" "$b" "$N"
done done
fi fi
if [ "${#ERRORS[@]}" -gt 0 ] && [ "${#BLOCKERS[@]}" -lt "${#ERRORS[@]}" ]; then 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 local e
for e in "${ERRORS[@]}"; do for e in "${ERRORS[@]}"; do
case "$e" in BLOCKER*) continue ;; esac case "$e" in BLOCKER*) continue ;; esac