Skip to content

Commit b19343c

Browse files
committed
ops: show broker connection in baudbot status
1 parent 02fe332 commit b19343c

3 files changed

Lines changed: 75 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sudo baudbot deploy
6868
# start the service
6969
sudo baudbot start
7070

71-
# check health
71+
# check health (includes deployed version + broker connection status)
7272
sudo baudbot status
7373
sudo baudbot doctor
7474
```

bin/baudbot

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ usage() {
103103
echo " start Start the agent (systemd, or --direct for foreground)"
104104
echo " stop Stop the agent"
105105
echo " restart Restart the agent"
106-
echo " status Show agent status + deployed version"
106+
echo " status Show agent status + deployed version + broker connection"
107107
echo " logs Tail agent logs"
108108
echo " attach Attach to control-agent by default; supports --pi/--tmux"
109109
echo " sessions List agent tmux and pi sessions (name → id)"
@@ -326,6 +326,76 @@ print_deployed_version() {
326326
echo -e "${BOLD}deployed version:${RESET} $line"
327327
}
328328

329+
is_broker_configured() {
330+
local agent_user="${1:-baudbot_agent}"
331+
local env_file="/home/$agent_user/.config/.env"
332+
local required_key=""
333+
local line=""
334+
local value=""
335+
336+
[ -r "$env_file" ] || return 1
337+
338+
for required_key in \
339+
SLACK_BROKER_URL \
340+
SLACK_BROKER_WORKSPACE_ID \
341+
SLACK_BROKER_SERVER_PRIVATE_KEY \
342+
SLACK_BROKER_SERVER_PUBLIC_KEY \
343+
SLACK_BROKER_SERVER_SIGNING_PRIVATE_KEY \
344+
SLACK_BROKER_PUBLIC_KEY \
345+
SLACK_BROKER_SIGNING_PUBLIC_KEY; do
346+
line="$(grep -E "^${required_key}=" "$env_file" | tail -1 || true)"
347+
[ -n "$line" ] || return 1
348+
349+
value="${line#*=}"
350+
value="${value//[[:space:]]/}"
351+
[ -n "$value" ] || return 1
352+
[ "$value" != "\"\"" ] || return 1
353+
[ "$value" != "''" ] || return 1
354+
done
355+
356+
return 0
357+
}
358+
359+
print_broker_connection_status() {
360+
local agent_user="${BAUDBOT_AGENT_USER:-baudbot_agent}"
361+
local pane=""
362+
local latest_signal=""
363+
364+
if ! is_broker_configured "$agent_user"; then
365+
echo -e "${BOLD}broker connection:${RESET} not configured"
366+
return 0
367+
fi
368+
369+
if [ "$(id -u)" -eq 0 ]; then
370+
if ! sudo -u "$agent_user" tmux has-session -t slack-bridge 2>/dev/null; then
371+
echo -e "${BOLD}broker connection:${RESET} disconnected (bridge tmux session not running)"
372+
return 0
373+
fi
374+
pane="$(sudo -u "$agent_user" tmux capture-pane -p -t slack-bridge -S -400 2>/dev/null || true)"
375+
elif [ "$(id -un)" = "$agent_user" ]; then
376+
if ! tmux has-session -t slack-bridge 2>/dev/null; then
377+
echo -e "${BOLD}broker connection:${RESET} disconnected (bridge tmux session not running)"
378+
return 0
379+
fi
380+
pane="$(tmux capture-pane -p -t slack-bridge -S -400 2>/dev/null || true)"
381+
else
382+
echo -e "${BOLD}broker connection:${RESET} configured (run with sudo for runtime status)"
383+
return 0
384+
fi
385+
386+
latest_signal="$(printf '%s\n' "$pane" | grep -E 'inbox poll failed|backing off|idle|pulled [0-9]+ message\(s\)|Slack broker pull bridge is running' | tail -1 || true)"
387+
388+
if printf '%s\n' "$latest_signal" | grep -Eq 'inbox poll failed|backing off'; then
389+
echo -e "${BOLD}broker connection:${RESET} reconnecting (recent inbox poll failure)"
390+
elif printf '%s\n' "$latest_signal" | grep -Eq 'idle|pulled [0-9]+ message\(s\)'; then
391+
echo -e "${BOLD}broker connection:${RESET} connected"
392+
elif printf '%s\n' "$latest_signal" | grep -q 'Slack broker pull bridge is running'; then
393+
echo -e "${BOLD}broker connection:${RESET} starting"
394+
else
395+
echo -e "${BOLD}broker connection:${RESET} unknown (bridge running, no recent poll telemetry)"
396+
fi
397+
}
398+
329399
pi_control_dir() {
330400
local agent_user="${1:-baudbot_agent}"
331401
echo "/home/$agent_user/.pi/session-control"
@@ -473,6 +543,7 @@ case "${1:-}" in
473543
systemctl status baudbot "$@" || status_rc=$?
474544
echo ""
475545
print_deployed_version
546+
print_broker_connection_status
476547
exit "$status_rc"
477548
else
478549
# Fallback: check if baudbot_agent has pi running
@@ -484,6 +555,7 @@ case "${1:-}" in
484555
fi
485556
echo ""
486557
print_deployed_version
558+
print_broker_connection_status
487559
fi
488560
;;
489561

docs/operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sudo baudbot start
1010
sudo baudbot stop
1111
sudo baudbot restart
1212

13-
# Status and logs
13+
# Status and logs (status includes deployed version + broker connection state)
1414
sudo baudbot status
1515
sudo baudbot logs
1616

0 commit comments

Comments
 (0)