mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-05 20:03:48 +00:00
Update notification service
This commit is contained in:
@@ -1093,7 +1093,7 @@ class HealthPersistence:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
# ─── System Capabilities Cache ───────────────────────────────
|
||||
# ─── System Capabilities Cache ───────────────────<EFBFBD><EFBFBD>───────────
|
||||
|
||||
def get_capability(self, cap_key: str) -> Optional[str]:
|
||||
"""
|
||||
@@ -1325,7 +1325,7 @@ class HealthPersistence:
|
||||
print(f"[HealthPersistence] Error recording UNKNOWN persistent: {e}")
|
||||
|
||||
|
||||
# ────────────────────────────────────────────<EFBFBD><EFBFBD><EFBFBD>───────────────────
|
||||
# ────────────────────────────────────────────────────────────────
|
||||
# Disk Observations API
|
||||
# ────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ def _format_vzdump_body(parsed: Dict[str, Any], is_success: bool) -> str:
|
||||
return '\n'.join(parts)
|
||||
|
||||
|
||||
# ─── Severity Icons ──────────────────────────────────────────────
|
||||
# ──<EFBFBD><EFBFBD> Severity Icons ──────────────────────────────────────────────
|
||||
|
||||
SEVERITY_ICONS = {
|
||||
'CRITICAL': '\U0001F534',
|
||||
|
||||
@@ -151,9 +151,6 @@ class ProxmoxStorageMonitor:
|
||||
storage_type = resource.get('plugintype', 'unknown')
|
||||
status = resource.get('status', 'unknown')
|
||||
|
||||
# Debug: log storage status during startup
|
||||
print(f"[v0] Storage '{name}': status={status}, maxdisk={resource.get('maxdisk', 0)}, node={node}")
|
||||
|
||||
try:
|
||||
total = int(resource.get('maxdisk', 0))
|
||||
used = int(resource.get('disk', 0))
|
||||
@@ -186,7 +183,6 @@ class ProxmoxStorageMonitor:
|
||||
storage_info['status'] = 'error'
|
||||
storage_info['status_detail'] = 'unavailable' if total == 0 else status
|
||||
unavailable_storages.append(storage_info)
|
||||
print(f"[v0] Storage '{name}' marked UNAVAILABLE: total={total}, status={status}")
|
||||
else:
|
||||
storage_info['status'] = 'active'
|
||||
available_storages.append(storage_info)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,14 @@
|
||||
#!/bin/bash
|
||||
# ProxMenux Monitor - Shutdown Notification Script
|
||||
# This script is called by systemd ExecStop before the service terminates.
|
||||
# It sends a shutdown/reboot notification via the running Flask server.
|
||||
# It sends a shutdown/reboot notification ONLY when the system is actually
|
||||
# shutting down or rebooting, NOT when the service is manually stopped.
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
CONFIG_DIR="/var/lib/proxmenux"
|
||||
CONFIG_FILE="$CONFIG_DIR/config.json"
|
||||
LOG_FILE="/var/log/proxmenux-shutdown.log"
|
||||
PORT="${PORT:-5000}"
|
||||
PORT="${PORT:-8008}"
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
@@ -16,19 +17,54 @@ log() {
|
||||
|
||||
log "=== Shutdown notification script started ==="
|
||||
|
||||
# Determine if this is a reboot or shutdown
|
||||
# Check for systemd targets or runlevel
|
||||
# Check if this is a real system shutdown/reboot or just a service stop
|
||||
# We only want to notify on actual system shutdown/reboot
|
||||
is_system_shutdown=false
|
||||
is_reboot=false
|
||||
|
||||
# Method 1: Check if shutdown/reboot targets are active or activating
|
||||
if systemctl is-active --quiet shutdown.target 2>/dev/null || \
|
||||
systemctl is-active --quiet poweroff.target 2>/dev/null || \
|
||||
systemctl is-active --quiet halt.target 2>/dev/null; then
|
||||
is_system_shutdown=true
|
||||
log "Detected: shutdown/poweroff/halt target is active"
|
||||
fi
|
||||
|
||||
if systemctl is-active --quiet reboot.target 2>/dev/null; then
|
||||
is_system_shutdown=true
|
||||
is_reboot=true
|
||||
log "Detected: reboot.target is active"
|
||||
elif [ -f /run/systemd/shutdown/scheduled ]; then
|
||||
fi
|
||||
|
||||
# Method 2: Check for scheduled shutdown file
|
||||
if [ -f /run/systemd/shutdown/scheduled ]; then
|
||||
is_system_shutdown=true
|
||||
if grep -q "reboot" /run/systemd/shutdown/scheduled 2>/dev/null; then
|
||||
is_reboot=true
|
||||
log "Detected: /run/systemd/shutdown/scheduled contains 'reboot'"
|
||||
else
|
||||
log "Detected: /run/systemd/shutdown/scheduled exists (shutdown)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Method 3: Check runlevel (0=halt, 6=reboot)
|
||||
runlevel_output=$(runlevel 2>/dev/null | awk '{print $2}')
|
||||
if [ "$runlevel_output" = "0" ]; then
|
||||
is_system_shutdown=true
|
||||
log "Detected: runlevel 0 (halt)"
|
||||
elif [ "$runlevel_output" = "6" ]; then
|
||||
is_system_shutdown=true
|
||||
is_reboot=true
|
||||
log "Detected: runlevel 6 (reboot)"
|
||||
fi
|
||||
|
||||
# If not a system shutdown, exit without sending notification
|
||||
if [ "$is_system_shutdown" = false ]; then
|
||||
log "Service stopped manually (not a system shutdown). No notification sent."
|
||||
log "=== Shutdown notification script completed (no action) ==="
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Build the event type and message
|
||||
if [ "$is_reboot" = true ]; then
|
||||
event_type="system_reboot"
|
||||
@@ -42,7 +78,6 @@ hostname=$(hostname)
|
||||
log "Event type: $event_type, Hostname: $hostname"
|
||||
|
||||
# Try to send notification via internal API endpoint
|
||||
# The Flask server may still be running at this point
|
||||
log "Sending notification to http://127.0.0.1:$PORT/api/internal/shutdown-event"
|
||||
|
||||
response=$(curl -s -w "\n%{http_code}" -X POST "http://127.0.0.1:$PORT/api/internal/shutdown-event" \
|
||||
@@ -66,10 +101,5 @@ fi
|
||||
log "Waiting 3 seconds for notification delivery..."
|
||||
sleep 3
|
||||
|
||||
# Now terminate the Flask process
|
||||
# Find the main process and send SIGTERM
|
||||
log "Terminating Flask process..."
|
||||
pkill -TERM -f "flask_server" 2>/dev/null || true
|
||||
|
||||
log "=== Shutdown notification script completed ==="
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user