From 132b4fb34bfc077997af559b07d0eacc1866dc69 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 16 Oct 2025 13:35:43 +0300 Subject: [PATCH] Proxmox HA: Fix false FAILED alerts and suppress cron notification emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed two critical issues with HA monitoring: 1. False positive quorum errors - corosync-quorumtool not in cron PATH 2. Unwanted cron emails from PVE::Notify INFO messages to STDERR Changes: - Set proper PATH including /usr/sbin for corosync-quorumtool - Split notification code: verbose shows all, non-verbose redirects STDERR to /dev/null - Prevents cron from sending duplicate notification emails 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- proxmox/ha-monitor.sh | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/proxmox/ha-monitor.sh b/proxmox/ha-monitor.sh index ba80ca1..5bfaa29 100644 --- a/proxmox/ha-monitor.sh +++ b/proxmox/ha-monitor.sh @@ -28,6 +28,9 @@ # ============= # Template-urile sunt create automat de script la prima rulare +# Set proper PATH for cron execution (includes /usr/sbin for corosync-quorumtool) +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + HOSTNAME=$(hostname) FQDN=$(hostname -f) DATE=$(date '+%Y-%m-%d %H:%M:%S') @@ -296,12 +299,14 @@ else fi # Trimite notificarea prin PVE::Notify cu tipul "ha-status" -perl -I/usr/share/perl5 << EOF +# Redirecționează STDERR către /dev/null pentru modul non-verbose (previne emailuri de la cron) +if [ "$1" == "--verbose" ] || [ "$1" == "-v" ]; then + # Modul verbose - afișează toate mesajele + perl -I/usr/share/perl5 << EOF use strict; use warnings; use PVE::Notify; -# Date pentru template (în format JSON-like pentru Perl) my \$template_data = { 'hostname' => '$FQDN', 'status' => '$STATUS', @@ -309,15 +314,12 @@ my \$template_data = { 'details' => '$DETAILS' }; -# Metadata pentru matcher my \$fields = { 'hostname' => '$HOSTNAME', 'type' => 'ha-status', 'status' => '$STATUS' }; -# Trimite notificarea cu tipul "ha-status" -# Va folosi template-urile din /etc/pve/notification-templates/default/ha-status-* eval { PVE::Notify::notify('$SEVERITY', 'ha-status', \$template_data, \$fields); print "Notification sent successfully\\n"; @@ -327,8 +329,37 @@ if (\$@) { exit 1; } EOF + PERL_EXIT_CODE=$? +else + # Modul non-verbose - suprimă mesajele INFO pentru a preveni emailuri de la cron + perl -I/usr/share/perl5 << EOF 2>/dev/null +use strict; +use warnings; +use PVE::Notify; -PERL_EXIT_CODE=$? +my \$template_data = { + 'hostname' => '$FQDN', + 'status' => '$STATUS', + 'runtime' => '$RUNTIME', + 'details' => '$DETAILS' +}; + +my \$fields = { + 'hostname' => '$HOSTNAME', + 'type' => 'ha-status', + 'status' => '$STATUS' +}; + +eval { + PVE::Notify::notify('$SEVERITY', 'ha-status', \$template_data, \$fields); +}; +if (\$@) { + print STDERR "Failed to send notification: \$@\\n"; + exit 1; +} +EOF + PERL_EXIT_CODE=$? +fi # Log local echo "$(date): HA status check completed - $STATUS, notification exit code: $PERL_EXIT_CODE" >> /var/log/pve-ha-monitor.log