Add UPS email notifications and automatic UPS shutdown
- Add email notifications via PVE::Notify for all UPS events: - ONBATT: when UPS switches to battery - ONLINE: when power is restored - LOWBATT: critical battery level - SHUTDOWN_START/NODE/PRIMARY: during cluster shutdown - COMMBAD: communication lost with UPS - Add automatic UPS shutdown command after cluster shutdown (protects against power surge when power returns) - Update upssched.conf with ONLINE handler and immediate ONBATT notification - Add notification templates for HTML and text emails - Update documentation with new features and timer configuration Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: #f5f5f5; }
|
||||
.container { max-width: 600px; margin: 0 auto; background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
|
||||
h1 { margin-top: 0; padding-bottom: 15px; border-bottom: 3px solid #3498db; }
|
||||
.status-onbatt { color: #e67e22; border-color: #e67e22; }
|
||||
.status-online { color: #27ae60; border-color: #27ae60; }
|
||||
.status-lowbatt { color: #c0392b; border-color: #c0392b; }
|
||||
.status-shutdown { color: #8e44ad; border-color: #8e44ad; }
|
||||
.alert-box { padding: 15px; border-radius: 5px; margin: 20px 0; border-left: 4px solid; }
|
||||
.alert-warning { background: #fef9e7; border-color: #f39c12; }
|
||||
.alert-danger { background: #fdedec; border-color: #e74c3c; }
|
||||
.alert-success { background: #eafaf1; border-color: #2ecc71; }
|
||||
.alert-info { background: #ebf5fb; border-color: #3498db; }
|
||||
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 20px 0; }
|
||||
.metric { background: #ecf0f1; padding: 15px; border-radius: 5px; text-align: center; }
|
||||
.metric-label { font-size: 12px; color: #7f8c8d; text-transform: uppercase; }
|
||||
.metric-value { font-size: 24px; font-weight: bold; color: #2c3e50; margin-top: 5px; }
|
||||
.footer { margin-top: 25px; padding-top: 15px; border-top: 1px solid #ecf0f1; font-size: 12px; color: #7f8c8d; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="status-{{ event_class }}">[UPS] {{ event_title }}</h1>
|
||||
|
||||
<p><strong>Hostname:</strong> {{ hostname }}<br>
|
||||
<strong>Date:</strong> {{ event_date }}<br>
|
||||
<strong>Event:</strong> {{ event_type }}</p>
|
||||
|
||||
<div class="alert-box alert-{{ alert_type }}">
|
||||
<strong>{{ event_description }}</strong>
|
||||
</div>
|
||||
|
||||
<h3>UPS Status</h3>
|
||||
<div class="metrics">
|
||||
<div class="metric">
|
||||
<div class="metric-label">Status</div>
|
||||
<div class="metric-value">{{ ups_status }}</div>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<div class="metric-label">Battery</div>
|
||||
<div class="metric-value">{{ battery_charge }}%</div>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<div class="metric-label">Input Voltage</div>
|
||||
<div class="metric-value">{{ input_voltage }}V</div>
|
||||
</div>
|
||||
{{#if battery_runtime}}
|
||||
<div class="metric">
|
||||
<div class="metric-label">Runtime</div>
|
||||
<div class="metric-value">{{ battery_runtime }} min</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#if action_taken}}
|
||||
<p><strong>Action:</strong> {{ action_taken }}</p>
|
||||
{{/if}}
|
||||
|
||||
{{#if next_steps}}
|
||||
<p><strong>Next Steps:</strong> {{ next_steps }}</p>
|
||||
{{/if}}
|
||||
|
||||
<div class="footer">
|
||||
<p>Log: /var/log/ups-events.log<br>
|
||||
Proxmox UPS Monitoring System</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,31 @@
|
||||
========================================
|
||||
UPS POWER EVENT - {{ event_title }}
|
||||
========================================
|
||||
|
||||
Hostname: {{ hostname }}
|
||||
Date: {{ event_date }}
|
||||
Event: {{ event_type }}
|
||||
|
||||
{{ event_description }}
|
||||
|
||||
UPS STATUS:
|
||||
-----------
|
||||
Status: {{ ups_status }}
|
||||
Battery Charge: {{ battery_charge }}%
|
||||
Input Voltage: {{ input_voltage }}V
|
||||
{{#if battery_runtime}}
|
||||
Battery Runtime: {{ battery_runtime }} min
|
||||
{{/if}}
|
||||
|
||||
{{#if action_taken}}
|
||||
ACTION: {{ action_taken }}
|
||||
{{/if}}
|
||||
|
||||
{{#if next_steps}}
|
||||
NEXT STEPS: {{ next_steps }}
|
||||
{{/if}}
|
||||
|
||||
========================================
|
||||
Log: /var/log/ups-events.log
|
||||
Script: /usr/local/bin/upssched-cmd
|
||||
========================================
|
||||
@@ -0,0 +1 @@
|
||||
[{{ hostname }}] UPS {{ event_type }} - {{ event_title }}
|
||||
@@ -6,15 +6,18 @@ CMDSCRIPT /usr/local/bin/upssched-cmd
|
||||
PIPEFN /run/nut/upssched.pipe
|
||||
LOCKFN /run/nut/upssched.lock
|
||||
|
||||
# Când UPS trece pe baterie (ONBATT), așteaptă 180 secunde (3 minute)
|
||||
# Dacă curentul revine în acest timp, anulează shutdown-ul
|
||||
# Când UPS trece pe baterie (ONBATT):
|
||||
# 1. Trimite notificare imediată
|
||||
# 2. Așteaptă 180 secunde (3 minute) înainte de shutdown
|
||||
AT ONBATT * EXECUTE onbatt_start
|
||||
AT ONBATT * START-TIMER onbatt 180
|
||||
|
||||
# Când UPS raportează baterie scăzută (LOWBATT), shutdown imediat
|
||||
AT LOWBATT * EXECUTE lowbatt
|
||||
|
||||
# Când curentul revine (ONLINE), anulează toate timer-ele
|
||||
# Când curentul revine (ONLINE), anulează timer-ele și trimite notificare
|
||||
AT ONLINE * CANCEL-TIMER onbatt
|
||||
AT ONLINE * EXECUTE online
|
||||
|
||||
# Când comunicația cu UPS se pierde (COMMBAD), așteaptă 30 secunde
|
||||
AT COMMBAD * START-TIMER commbad 30
|
||||
|
||||
Reference in New Issue
Block a user