Files
homelab-monitoring/scripts/check-network.sh
PVE Monitoring System 3a14fd2736 Initial backup: 18 monitoring scripts + timers + docs
- 18 comprehensive monitoring checks
- 5 systemd timers (5min, 15min, hourly, daily, weekly)
- Complete documentation
- NTFY secure notification system
- Fixed debianvm disk space (91% to 57%)
- Fixed CloudReve integration
- Date: 2026-01-07
2026-01-07 16:30:34 +08:00

45 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Monitor public IP and internet speed
set -euo pipefail
SEND_NTFY="/usr/local/bin/send-ntfy.sh"
CACHE_FILE="/var/cache/public_ip_pve"
# Check public IP
CURRENT_IP=$(timeout 10 curl -s https://ifconfig.me 2>/dev/null || echo "FAILED")
if [ "$CURRENT_IP" = "FAILED" ]; then
$SEND_NTFY warning "Internet Check Failed" "🟡 WARNING: Cannot detect public IP - internet connection issue?" "warning,globe_with_meridians"
exit 1
fi
# Check if IP changed
if [ -f "$CACHE_FILE" ]; then
OLD_IP=$(cat "$CACHE_FILE")
if [ "$CURRENT_IP" != "$OLD_IP" ]; then
$SEND_NTFY info "Public IP Changed" " INFO: Homelab public IP changed\nOld: $OLD_IP\nNew: $CURRENT_IP" "globe_with_meridians,info"
fi
fi
echo "$CURRENT_IP" > "$CACHE_FILE"
# Speed test (only if --speedtest flag passed)
if [ "${1:-}" = "--speedtest" ]; then
if command -v speedtest-cli &>/dev/null; then
SPEED_RESULT=$(speedtest-cli --simple 2>/dev/null || echo "FAILED")
if [ "$SPEED_RESULT" != "FAILED" ]; then
UPLOAD=$(echo "$SPEED_RESULT" | grep "Upload:" | awk '{print $2}')
UPLOAD_INT=${UPLOAD%.*}
if [ "$UPLOAD_INT" -lt 10 ]; then
$SEND_NTFY warning "Slow Internet Speed" "🟡 WARNING: Upload speed only $UPLOAD Mbit/s (< 10 Mbit/s)" "snail,warning,globe_with_meridians"
else
$SEND_NTFY info "Speed Test Result" " INFO: Internet speed test\n$SPEED_RESULT" "globe_with_meridians,zap"
fi
fi
fi
fi
logger -t network-monitor "Public IP: $CURRENT_IP"