#!/bin/sh
# xfce4-genmon panel indicator โ polls colibri daemon health.
# Install: add a Generic Monitor panel item pointing to this script.
# Refresh interval: 30s.
#
# Output: green/red dot + agent count + task count.
# ๐ข 2 agents ยท 3 tasks
# ๐ด daemon down
SOCKET="${COLIBRI_SOCKET:-/var/run/colibri/colibri.sock}"
TOOLTIP=""
if [ -S "$SOCKET" ]; then
STATUS=$(printf '{"cmd":"status"}\n' | nc -U "$SOCKET" -w 2 2>/dev/null)
if [ -n "$STATUS" ]; then
AGENTS=$(echo "$STATUS" | python3 -c "import sys,json; d=json.load(sys.stdin)['data']; print(d['agents'])" 2>/dev/null)
TASKS=$(echo "$STATUS" | python3 -c "import sys,json; d=json.load(sys.stdin)['data']; t=d['tasks']; print(t['started'])" 2>/dev/null)
HOST=$(echo "$STATUS" | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['host'])" 2>/dev/null)
echo "๐ข ${AGENTS} agents ยท ${TASKS} tasks"
TOOLTIP="Colibri: ${HOST} | socket: ${SOCKET} | agents: ${AGENTS} | started tasks: ${TASKS}"
else
echo "๐ด no response"
TOOLTIP="Colibri socket exists but not responding"
fi
else
echo "๐ด down"
TOOLTIP="Colibri daemon not running (no socket at ${SOCKET})"
fi
echo "${TOOLTIP}"
echo "xfce4-terminal --title 'Colibri Status' --command 'colibri status'"