Fix UPS notifications and add periodic battery status emails
- Fix permission denied on log files (chown nut:nut) - Fix upssched.conf permissions (root:nut) - Add sudo for perl to allow PVE::Notify from user nut - Add periodic battery status emails every minute when on battery - Add charging status emails at 5, 10, 30 min after power restore - Remove diacritics from all notification messages - Update documentation with sudo and permissions setup Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
# Trimite notificari email via PVE::Notify pentru fiecare pas
|
||||
#
|
||||
# Creat: 2025-10-06
|
||||
# Actualizat: 2026-01-13 - Adaugat notificari email si UPS shutdown
|
||||
# Actualizat: 2026-01-14 - Fix permisiuni log file, adaugat sudo pentru PVE::Notify
|
||||
|
||||
LOGFILE=/var/log/ups-shutdown.log
|
||||
NODES=("10.0.20.200" "10.0.20.202") # pve1, pveelite (pvemini va fi ultimul)
|
||||
@@ -16,8 +16,22 @@ TEMPLATE_DIR="/etc/pve/notification-templates/default"
|
||||
HOSTNAME=$(hostname)
|
||||
FQDN=$(hostname -f 2>/dev/null || hostname)
|
||||
|
||||
# Asigura ca fisierul de log exista si are permisiunile corecte
|
||||
# Scriptul poate rula ca user 'nut', deci fisierul trebuie sa fie writable
|
||||
ensure_logfile() {
|
||||
if [ ! -f "$LOGFILE" ]; then
|
||||
touch "$LOGFILE" 2>/dev/null || sudo touch "$LOGFILE"
|
||||
fi
|
||||
if [ ! -w "$LOGFILE" ]; then
|
||||
sudo chown nut:nut "$LOGFILE" 2>/dev/null
|
||||
sudo chmod 664 "$LOGFILE" 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
ensure_logfile
|
||||
|
||||
log_message() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a $LOGFILE
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a $LOGFILE 2>/dev/null
|
||||
logger -t ups-shutdown "$1"
|
||||
}
|
||||
|
||||
@@ -42,7 +56,7 @@ send_notification() {
|
||||
|
||||
log_message "Sending notification: $EVENT_TITLE"
|
||||
|
||||
perl -I/usr/share/perl5 << EOFPERL 2>&1 | tee -a $LOGFILE
|
||||
/usr/bin/sudo /usr/bin/perl -I/usr/share/perl5 << EOFPERL 2>&1 | tee -a $LOGFILE
|
||||
use strict;
|
||||
use warnings;
|
||||
use PVE::Notify;
|
||||
|
||||
Reference in New Issue
Block a user