@@ -326,74 +326,55 @@ 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-
329+ broker_mode_configured () {
330+ local env_file=" /home/${1:- baudbot_agent} /.config/.env"
336331 [ -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
332+ grep -Eq ' ^SLACK_BROKER_URL=[^[:space:]].*$' " $env_file " || return 1
333+ grep -Eq ' ^SLACK_BROKER_WORKSPACE_ID=[^[:space:]].*$' " $env_file " || return 1
357334}
358335
359336print_broker_connection_status () {
360337 local agent_user=" ${BAUDBOT_AGENT_USER:- baudbot_agent} "
361338 local pane=" "
362339 local latest_signal=" "
363340
364- if ! is_broker_configured " $agent_user " ; then
341+ if ! broker_mode_configured " $agent_user " ; then
365342 echo -e " ${BOLD} broker connection:${RESET} not configured"
366343 return 0
367344 fi
368345
369346 if [ " $( id -u) " -eq 0 ]; then
370- if ! sudo -u " $agent_user " tmux has-session -t slack-bridge 2> /dev/null; then
347+ sudo -u " $agent_user " tmux has-session -t slack-bridge 2> /dev/null || {
371348 echo -e " ${BOLD} broker connection:${RESET} disconnected (bridge tmux session not running)"
372349 return 0
373- fi
374- pane=" $( sudo -u " $agent_user " tmux capture-pane -p -t slack-bridge -S -400 2> /dev/null || true) "
350+ }
351+ pane=" $( sudo -u " $agent_user " tmux capture-pane -p -t slack-bridge -S -200 2> /dev/null || true) "
375352 elif [ " $( id -un) " = " $agent_user " ]; then
376- if ! tmux has-session -t slack-bridge 2> /dev/null; then
353+ tmux has-session -t slack-bridge 2> /dev/null || {
377354 echo -e " ${BOLD} broker connection:${RESET} disconnected (bridge tmux session not running)"
378355 return 0
379- fi
380- pane=" $( tmux capture-pane -p -t slack-bridge -S -400 2> /dev/null || true) "
356+ }
357+ pane=" $( tmux capture-pane -p -t slack-bridge -S -200 2> /dev/null || true) "
381358 else
382359 echo -e " ${BOLD} broker connection:${RESET} configured (run with sudo for runtime status)"
383360 return 0
384361 fi
385362
386363 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
364+ case " $latest_signal " in
365+ * " inbox poll failed" * |* " backing off" * )
366+ echo -e " ${BOLD} broker connection:${RESET} reconnecting (recent inbox poll failure)"
367+ ;;
368+ * " idle" * |* " pulled " * )
369+ echo -e " ${BOLD} broker connection:${RESET} connected"
370+ ;;
371+ * " Slack broker pull bridge is running" * )
372+ echo -e " ${BOLD} broker connection:${RESET} starting"
373+ ;;
374+ * )
375+ echo -e " ${BOLD} broker connection:${RESET} unknown (bridge running, no recent poll telemetry)"
376+ ;;
377+ esac
397378}
398379
399380pi_control_dir () {
0 commit comments