Files
homelab-monitoring/scripts/check-failed-logins.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

23 lines
839 B
Bash
Executable File
Raw 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 failed login attempts
set -u
SEND_NTFY="/usr/local/bin/send-ntfy.sh"
# Count failures
FAILED_SSH=$(journalctl -u ssh --since "1 hour ago" 2>/dev/null | grep -c "Failed password" || true)
FAILED_WEB=$(journalctl --since "1 hour ago" 2>/dev/null | grep -c "authentication failure.*pvedaemon" || true)
FAILED_SSH=${FAILED_SSH:-0}
FAILED_WEB=${FAILED_WEB:-0}
TOTAL_FAILED=$((FAILED_SSH + FAILED_WEB))
if [ $TOTAL_FAILED -gt 20 ]; then
$SEND_NTFY warning "Brute Force Attack" "🟡 WARNING: $TOTAL_FAILED failed logins!\nSSH: $FAILED_SSH, Web: $FAILED_WEB" "warning,lock"
elif [ $TOTAL_FAILED -gt 10 ]; then
$SEND_NTFY info "Failed Logins" " INFO: $TOTAL_FAILED failed logins\nSSH: $FAILED_SSH, Web: $FAILED_WEB" "lock,info"
fi
logger -t login-monitor "Failed logins: SSH=$FAILED_SSH, Web=$FAILED_WEB"