Using Fit-statUSB to provide visual server health in my homelab using proxmox
#!/bin/bash
# Define color variables
BLUE="000011"
RED="010000"
YELLOW="050500"
GREEN="000100"
WHITE="111111"
OFF="000000"
DECAY="#FF0000"
# Initialize the serial port
usbreset fit_StatUSB
if [ $? -ne 0 ]; then
echo "Device not found. Aborting."
exit 1
fi
sleep 5
stty -F /dev/ttyACM0 9600 raw -echo -echoe -echok -echoctl -echoke
sleep 5
# Function to send a color command to Fit-statUSB
send_color() {
echo Sending: "B#${1}-250#000000-1000${DECAY}-9999"
echo -e "B#${1}-250#000000-1000${DECAY}-9999" > /dev/ttyACM0
sleep 1
}
echo -e "F0001" > /dev/ttyACM0; sleep 1 # Minimal Transition
echo -e "#${RED}" > /dev/ttyACM0; sleep 1 # Red
echo -e "#${GREEN}" > /dev/ttyACM0; sleep 1 # Green
echo -e "#${BLUE}" > /dev/ttyACM0; sleep 1 # Blue
echo -e "#${WHITE}" > /dev/ttyACM0; sleep 1 # White
echo -e "#${OFF}" > /dev/ttyACM0; sleep 1 # Off
while true; do
# Get processor idle time using vmstat
idle=$(vmstat 1 2 | tail -1 | awk '{print $15}')
# Get Proxmox health state
expected_votes=$(pvecm status | grep 'Expected votes:' | awk '{print $2}')
total_votes=$(pvecm status | grep 'Total votes:' | awk '{print $2}')
flags=$(pvecm status | grep 'Flags:' | awk '{print $2}')
if [ "$flags" != "Quorate" ]; then
proxmox_status="$RED"
elif [ "$expected_votes" != "$total_votes" ]; then
proxmox_status="$YELLOW"
else
proxmox_status="$GREEN"
fi
# Check network connectivity
if ping -c 1 8.8.8.8 &> /dev/null; then
network_status="$GREEN"
else
network_status="$RED"
fi
# Determine processor state color
if [ "$idle" -lt 10 ]; then
processor_status="$RED"
elif [ "$idle" -lt 20 ]; then
processor_status="$YELLOW"
else
processor_status="$GREEN"
fi
# Repeat the sequences 6 times before re-evaluating the system state
for i in {1..6}; do
# Create and send blink sequence with breaks
send_color "$BLUE" # Initial Blue indicating start of the dataset
send_color "$processor_status"
send_color "$proxmox_status"
send_color "$network_status"
done
done
0