mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-18 10:02:16 +00:00
Utdate notification service
This commit is contained in:
@@ -1325,7 +1325,7 @@ class HealthPersistence:
|
|||||||
print(f"[HealthPersistence] Error recording UNKNOWN persistent: {e}")
|
print(f"[HealthPersistence] Error recording UNKNOWN persistent: {e}")
|
||||||
|
|
||||||
|
|
||||||
# ────────────────────────────────────────────────────────────────
|
# ───────────────────────────────────────────────────────────────<EFBFBD><EFBFBD>
|
||||||
# Disk Observations API
|
# Disk Observations API
|
||||||
# ────────────────────────────────────────────────────────────────
|
# ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -1043,8 +1043,16 @@ class NotificationManager:
|
|||||||
entity_id=entity_id,
|
entity_id=entity_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process the event through the normal pipeline
|
# For urgent events (shutdown/reboot), dispatch directly to ensure
|
||||||
return self._process_single_event(event)
|
# immediate delivery before the system goes down.
|
||||||
|
# For other events, use the normal pipeline with aggregation.
|
||||||
|
_URGENT_EVENTS = {'system_shutdown', 'system_reboot'}
|
||||||
|
if event_type in _URGENT_EVENTS:
|
||||||
|
self._dispatch_event(event)
|
||||||
|
return {'success': True, 'event_type': event_type, 'dispatched': 'direct'}
|
||||||
|
else:
|
||||||
|
self._process_event(event)
|
||||||
|
return {'success': True, 'event_type': event_type, 'dispatched': 'queued'}
|
||||||
|
|
||||||
def send_notification(self, event_type: str, severity: str,
|
def send_notification(self, event_type: str, severity: str,
|
||||||
title: str, message: str,
|
title: str, message: str,
|
||||||
|
|||||||
@@ -6,16 +6,26 @@
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
CONFIG_DIR="/var/lib/proxmenux"
|
CONFIG_DIR="/var/lib/proxmenux"
|
||||||
CONFIG_FILE="$CONFIG_DIR/config.json"
|
CONFIG_FILE="$CONFIG_DIR/config.json"
|
||||||
|
LOG_FILE="/var/log/proxmenux-shutdown.log"
|
||||||
PORT="${PORT:-5000}"
|
PORT="${PORT:-5000}"
|
||||||
|
|
||||||
|
# Logging function
|
||||||
|
log() {
|
||||||
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE" 2>/dev/null || true
|
||||||
|
}
|
||||||
|
|
||||||
|
log "=== Shutdown notification script started ==="
|
||||||
|
|
||||||
# Determine if this is a reboot or shutdown
|
# Determine if this is a reboot or shutdown
|
||||||
# Check for systemd targets or runlevel
|
# Check for systemd targets or runlevel
|
||||||
is_reboot=false
|
is_reboot=false
|
||||||
if systemctl is-active --quiet reboot.target 2>/dev/null; then
|
if systemctl is-active --quiet reboot.target 2>/dev/null; then
|
||||||
is_reboot=true
|
is_reboot=true
|
||||||
|
log "Detected: reboot.target is active"
|
||||||
elif [ -f /run/systemd/shutdown/scheduled ]; then
|
elif [ -f /run/systemd/shutdown/scheduled ]; then
|
||||||
if grep -q "reboot" /run/systemd/shutdown/scheduled 2>/dev/null; then
|
if grep -q "reboot" /run/systemd/shutdown/scheduled 2>/dev/null; then
|
||||||
is_reboot=true
|
is_reboot=true
|
||||||
|
log "Detected: /run/systemd/shutdown/scheduled contains 'reboot'"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -29,19 +39,37 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
hostname=$(hostname)
|
hostname=$(hostname)
|
||||||
|
log "Event type: $event_type, Hostname: $hostname"
|
||||||
|
|
||||||
# Try to send notification via internal API endpoint
|
# Try to send notification via internal API endpoint
|
||||||
# The Flask server may still be running at this point
|
# The Flask server may still be running at this point
|
||||||
curl -s -X POST "http://127.0.0.1:$PORT/api/internal/shutdown-event" \
|
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" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"event_type\": \"$event_type\", \"hostname\": \"$hostname\", \"reason\": \"$reason\"}" \
|
-d "{\"event_type\": \"$event_type\", \"hostname\": \"$hostname\", \"reason\": \"$reason\"}" \
|
||||||
--max-time 5 2>/dev/null || true
|
--max-time 10 2>&1)
|
||||||
|
|
||||||
|
http_code=$(echo "$response" | tail -n1)
|
||||||
|
body=$(echo "$response" | head -n -1)
|
||||||
|
|
||||||
|
log "Response HTTP code: $http_code"
|
||||||
|
log "Response body: $body"
|
||||||
|
|
||||||
|
if [ "$http_code" = "200" ]; then
|
||||||
|
log "Notification sent successfully"
|
||||||
|
else
|
||||||
|
log "WARNING: Notification may have failed (HTTP $http_code)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Give the notification a moment to be sent
|
# Give the notification a moment to be sent
|
||||||
sleep 2
|
log "Waiting 3 seconds for notification delivery..."
|
||||||
|
sleep 3
|
||||||
|
|
||||||
# Now terminate the Flask process
|
# Now terminate the Flask process
|
||||||
# Find the main process and send SIGTERM
|
# Find the main process and send SIGTERM
|
||||||
pkill -TERM -f "proxmenux-monitor" 2>/dev/null || true
|
log "Terminating Flask process..."
|
||||||
|
pkill -TERM -f "flask_server" 2>/dev/null || true
|
||||||
|
|
||||||
|
log "=== Shutdown notification script completed ==="
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ NC='\033[0m'
|
|||||||
API="http://127.0.0.1:8008"
|
API="http://127.0.0.1:8008"
|
||||||
LOG_FILE="/tmp/proxmenux_real_test_$(date +%Y%m%d_%H%M%S).log"
|
LOG_FILE="/tmp/proxmenux_real_test_$(date +%Y%m%d_%H%M%S).log"
|
||||||
|
|
||||||
# ── Helpers ─────────────────────────────────────────────────────
|
# ── Helpers ─────────────────────<EFBFBD><EFBFBD><EFBFBD>───────────────────────────────
|
||||||
log() { echo -e "$1" | tee -a "$LOG_FILE"; }
|
log() { echo -e "$1" | tee -a "$LOG_FILE"; }
|
||||||
header() {
|
header() {
|
||||||
echo "" | tee -a "$LOG_FILE"
|
echo "" | tee -a "$LOG_FILE"
|
||||||
|
|||||||
Reference in New Issue
Block a user