Proxmox HA: Fix false FAILED alerts and suppress cron notification emails
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user