Fix agent fleet verification via Redis container
This commit is contained in:
parent
b129f03837
commit
c299a2cb85
|
|
@ -1,44 +1,68 @@
|
|||
#!/usr/bin/env bash
|
||||
# verify-agent-fleet.sh - Check the status of stability agents across the fleet
|
||||
|
||||
REDIS_HOST="100.108.208.3"
|
||||
REDIS_PORT="6379"
|
||||
REDIS_CMD="docker exec agent-system-redis redis-cli --raw"
|
||||
|
||||
echo "--- Homelab Agent Fleet Status ---"
|
||||
|
||||
# Check if redis-cli is available
|
||||
if ! command -v redis-cli &> /dev/null; then
|
||||
echo "Error: redis-cli not found. Please install it or run this on a node with Redis access."
|
||||
echo "Expected Redis: $REDIS_HOST:$REDIS_PORT"
|
||||
# Check if docker is available
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Error: docker command not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NODES=$(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --raw KEYS 'homelab:nodes:*' | sed 's/homelab:nodes://')
|
||||
|
||||
if [[ -z "$NODES" ]]; then
|
||||
echo "No nodes found in Redis."
|
||||
exit 0
|
||||
# Check if container is running
|
||||
if ! docker ps --filter "name=agent-system-redis" --format "{{.Names}}" | grep -q "agent-system-redis"; then
|
||||
echo "Error: agent-system-redis container not found or not running."
|
||||
echo "This script must be run on PIHA (the node hosting the Redis container)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "%-15s | %-10s | %-20s | %-10s\n" "NODE" "STATUS" "LAST HEARTBEAT" "DOCKER"
|
||||
REQUIRED_NODES=("piha" "chelsty" "solaria" "vps")
|
||||
MISSING_NODES=0
|
||||
|
||||
echo "--- Homelab Agent Fleet Status ---"
|
||||
printf "%-10s %-15s %-10s %-10s %-30s\n" "NODE" "HOSTNAME" "HEALTH" "STATUS" "LAST_SEEN"
|
||||
printf "%s\n" "--------------------------------------------------------------------------------"
|
||||
|
||||
for NODE in $NODES; do
|
||||
DATA=$(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" HGETALL "homelab:nodes:$NODE")
|
||||
for NODE in "${REQUIRED_NODES[@]}"; do
|
||||
KEY="homelab:nodes:$NODE"
|
||||
|
||||
# Simple parser for HGETALL output (alternating key/value)
|
||||
STATUS=$(echo "$DATA" | grep -A 1 "status" | tail -n 1)
|
||||
HEARTBEAT=$(echo "$DATA" | grep -A 1 "timestamp" | tail -n 1)
|
||||
CHECKS=$(echo "$DATA" | grep -A 1 "checks" | tail -n 1)
|
||||
|
||||
DOCKER_STATUS="unknown"
|
||||
if [[ "$CHECKS" == *"docker"* ]]; then
|
||||
DOCKER_STATUS=$(echo "$CHECKS" | jq -r '.docker.status' 2>/dev/null || echo "error")
|
||||
# Check if key exists
|
||||
EXISTS=$($REDIS_CMD EXISTS "$KEY" 2>/dev/null | tr -d '\r\n')
|
||||
|
||||
if [[ "$EXISTS" != "1" ]]; then
|
||||
printf "%-10s %-15s %-10s %-10s %-30s\n" "$NODE" "MISSING" "N/A" "N/A" "N/A"
|
||||
MISSING_NODES=$((MISSING_NODES + 1))
|
||||
continue
|
||||
fi
|
||||
|
||||
printf "%-15s | %-10s | %-20s | %-10s\n" "$NODE" "$STATUS" "$HEARTBEAT" "$DOCKER_STATUS"
|
||||
HOSTNAME=$($REDIS_CMD HGET "$KEY" hostname 2>/dev/null | tr -d '\r\n')
|
||||
HEALTH=$($REDIS_CMD HGET "$KEY" health 2>/dev/null | tr -d '\r\n')
|
||||
STATUS=$($REDIS_CMD HGET "$KEY" status 2>/dev/null | tr -d '\r\n')
|
||||
LAST_SEEN=$($REDIS_CMD HGET "$KEY" last_seen 2>/dev/null | tr -d '\r\n')
|
||||
|
||||
printf "%-10s %-15s %-10s %-10s %-30s\n" "$NODE" "$HOSTNAME" "$HEALTH" "$STATUS" "$LAST_SEEN"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Events (last 5):"
|
||||
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" XREVRANGE homelab:events + - COUNT 5
|
||||
echo "--- Control Plane Summary ---"
|
||||
if command -v jq >/dev/null; then
|
||||
curl -s http://127.0.0.1:18180/summary | jq .
|
||||
else
|
||||
curl -s http://127.0.0.1:18180/summary
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "--- Control Plane Nodes ---"
|
||||
if command -v jq >/dev/null; then
|
||||
curl -s http://127.0.0.1:18180/nodes | jq .
|
||||
else
|
||||
curl -s http://127.0.0.1:18180/nodes
|
||||
fi
|
||||
|
||||
if [[ $MISSING_NODES -gt 0 ]]; then
|
||||
echo ""
|
||||
echo "Error: $MISSING_NODES required nodes are missing from Redis."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue