diff --git a/scripts/taler-monitoring/lib.sh b/scripts/taler-monitoring/lib.sh index 5df0819..a4c516a 100755 --- a/scripts/taler-monitoring/lib.sh +++ b/scripts/taler-monitoring/lib.sh @@ -352,17 +352,19 @@ koopa_ssh_python() { with_timeout "$t" ssh "${SSH_BASE_OPTS[@]}" "${KOOPA_SSH}" python3 - } -# ANSI colours for tags (green OK / yellow WARN / red ERROR·BLOCKER / cyan INFO). -# Default: always on so pasted logs keep visible tags. Disable: NO_COLOR=1 or CLICOLOR=0. +# ANSI colours — tag + body (label bold, detail dim). Off: NO_COLOR=1 or CLICOLOR=0. if [ "${NO_COLOR:-0}" = "1" ] || [ "${CLICOLOR:-1}" = "0" ]; then - G= R= Y= C= N= B= + G= R= Y= C= M= D= W= B= N= else - G=$'\e[1;32m' # bold green [OK] - R=$'\e[1;31m' # bold red [ERROR] [BLOCKER] - Y=$'\e[1;33m' # bold yellow [WARN] - C=$'\e[1;36m' # bold cyan [INFO] - B=$'\e[1m' - N=$'\e[0m' + 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 fi PASS_N=0 @@ -392,47 +394,54 @@ _take_tid() { TEST_N=$((TEST_N + 1)) LAST_TID=$(printf '%s-%03d' "$TEST_AREA" "$TEST_N") } +# Dim test id: "www-001 " or empty _fmt_tid() { - # prefix "www-001 " or empty if [ -n "${LAST_TID:-}" ]; then - printf '%s ' "$LAST_TID" + printf '%s%s%s ' "$D" "$LAST_TID" "$N" + fi +} +# One concrete line: [TAG] tid label · detail +# $1=tag colour $2=tag text $3=label colour $4=label $5=detail (optional) +_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 tcell + tcell=$(printf '%-9s' "[${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" + else + printf '%s%s%s %s%s%s%s\n' \ + "$tcol" "$tcell" "$N" "$(_fmt_tid)" "$lcol" "$label" "$N" fi } ok() { - # Forms (same idea as info/warn): - # ok "what passed" - # ok "what passed" "detail / ms / bytes / …" + # ok "what is good" ["concrete evidence: HTTP 200 · 12ms · …"] local label="$1" detail="${2:-}" _take_tid - if [ -n "$detail" ]; then - printf '%s[OK]%s %s%s — %s\n' "$G" "$N" "$(_fmt_tid)" "$label" "$detail" - else - printf '%s[OK]%s %s%s\n' "$G" "$N" "$(_fmt_tid)" "$label" - fi + _msg_line "$G" "OK" "$W" "$label" "$detail" PASS_N=$((PASS_N + 1)) } -# component-scoped error: err bank "libeufin down" "detail" +# component-scoped error: err bank "what failed" "why / HTTP / path" err() { local comp="$1" msg="$2" detail="${3:-}" _take_tid - printf '%s[ERROR]%s %s%s: %s%s\n' "$R" "$N" "$(_fmt_tid)" "$comp" "$msg" "${detail:+ — $detail}" + _msg_line "$R" "ERROR" "$W" "${comp}: ${msg}" "$detail" FAIL_N=$((FAIL_N + 1)) - ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ — $detail}") + ERRORS+=("${LAST_TID:+$LAST_TID }[$comp] $msg${detail:+ · $detail}") } -# legacy fail label ... +# fail "what failed" ["why / HTTP code / path"] fail() { local label="$1" detail="${2:-}" _take_tid - printf '%s[ERROR]%s %s%s%s\n' "$R" "$N" "$(_fmt_tid)" "$label" "${detail:+ — $detail}" + _msg_line "$R" "ERROR" "$W" "$label" "$detail" FAIL_N=$((FAIL_N + 1)) - ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ — $detail}") + ERRORS+=("${LAST_TID:+$LAST_TID }$label${detail:+ · $detail}") } warn() { - # Forms (same idea as err; always try to state the problem): - # warn "problem" - # warn "problem" "why / context" - # warn component "problem" "why / context" + # warn "what is soft-bad" ["why still ok to continue"] + # warn component "what" "why" local a1="${1:-}" a2="${2:-}" a3="${3:-}" local head detail _take_tid @@ -446,56 +455,51 @@ warn() { head="$a1" detail="" fi - if [ -n "$detail" ]; then - printf '%s[WARN]%s %s%s — %s\n' "$Y" "$N" "$(_fmt_tid)" "$head" "$detail" - else - printf '%s[WARN]%s %s%s\n' "$Y" "$N" "$(_fmt_tid)" "$head" - fi + _msg_line "$Y" "WARN" "$W" "$head" "$detail" WARN_N=$((WARN_N + 1)) } info() { + # info "topic" ["concrete fact / value / next step"] local label="$1" detail="${2:-}" _take_tid - if [ -n "$detail" ]; then - printf '%s[INFO]%s %s%s — %s\n' "$C" "$N" "$(_fmt_tid)" "$label" "$detail" - else - printf '%s[INFO]%s %s%s\n' "$C" "$N" "$(_fmt_tid)" "$label" - fi + _msg_line "$C" "INFO" "$W" "$label" "$detail" INFO_N=$((INFO_N + 1)) } blocker() { - # Payment/withdraw path cannot proceed because of this + # Hard stop on pay/withdraw path: blocker "step" "why it cannot continue" local step="$1" msg="$2" _take_tid - printf '%s[BLOCKER]%s %s%s: %s\n' "$R$B" "$N" "$(_fmt_tid)" "$step" "$msg" + _msg_line "$M" "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\n' "$B" "$*" "$N"; } +section() { + printf '\n%s==%s %s%s%s %s==%s\n' "$D" "$N" "$B" "$*" "$N" "$D" "$N" +} summary() { echo "" if [ "${#BLOCKERS[@]}" -gt 0 ]; then - printf '%s--- BLOCKERS (fix/withdraw path) ---%s\n' "$R$B" "$N" + printf '%s--- BLOCKERS%s %s(pay/withdraw cannot finish)%s %s---%s\n' "$M" "$N" "$D" "$N" "$M" "$N" local b for b in "${BLOCKERS[@]}"; do - printf '%s • %s%s\n' "$R" "$b" "$N" + 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\n' "$R" "$N" + printf '%s--- ERRORS%s %s(failed checks)%s %s---%s\n' "$R" "$N" "$D" "$N" "$R" "$N" local e for e in "${ERRORS[@]}"; do case "$e" in BLOCKER*) continue ;; esac - printf '%s • %s%s\n' "$R" "$e" "$N" + printf '%s •%s %s%s%s\n' "$R" "$N" "$W" "$e" "$N" done fi - printf 'totals: %s%d OK%s' "$G" "$PASS_N" "$N" + printf '%stotals:%s %s%d OK%s' "$D" "$N" "$G" "$PASS_N" "$N" [ "$FAIL_N" -gt 0 ] && printf ', %s%d ERROR%s' "$R" "$FAIL_N" "$N" [ "$WARN_N" -gt 0 ] && printf ', %s%d WARN%s' "$Y" "$WARN_N" "$N" - [ "$INFO_N" -gt 0 ] && printf ', %d INFO' "$INFO_N" - [ "${#BLOCKERS[@]}" -gt 0 ] && printf ', %s%d BLOCKER%s' "$R" "${#BLOCKERS[@]}" "$N" + [ "$INFO_N" -gt 0 ] && printf ', %s%d INFO%s' "$C" "$INFO_N" "$N" + [ "${#BLOCKERS[@]}" -gt 0 ] && printf ', %s%d BLOCKER%s' "$M" "${#BLOCKERS[@]}" "$N" printf '\n' [ "$FAIL_N" -eq 0 ] }