From 5138b2f1d5a227066e44b2cc25aafc3e655b0e3e Mon Sep 17 00:00:00 2001 From: MacRimi Date: Tue, 31 Mar 2026 20:55:17 +0200 Subject: [PATCH] update health_persistence.py --- AppImage/scripts/flask_notification_routes.py | 2 +- AppImage/scripts/health_persistence.py | 43 ++++++++++++++----- AppImage/scripts/notification_templates.py | 2 +- AppImage/scripts/startup_grace.py | 2 +- AppImage/scripts/test_real_events.sh | 2 +- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/AppImage/scripts/flask_notification_routes.py b/AppImage/scripts/flask_notification_routes.py index 9307a7e8..7c3294b7 100644 --- a/AppImage/scripts/flask_notification_routes.py +++ b/AppImage/scripts/flask_notification_routes.py @@ -855,7 +855,7 @@ def proxmox_webhook(): resp.headers['Retry-After'] = '60' return resp, 429 - # ��─ Layers 2-5: Remote-only checks ── + # ── Layers 2-5: Remote-only checks ── if not is_localhost: # Layer 2: Shared secret try: diff --git a/AppImage/scripts/health_persistence.py b/AppImage/scripts/health_persistence.py index 4bed6401..132b9c2d 100644 --- a/AppImage/scripts/health_persistence.py +++ b/AppImage/scripts/health_persistence.py @@ -1182,41 +1182,62 @@ class HealthPersistence: return True return False - except Exception: - # On error, assume it exists to avoid false positives + except subprocess.TimeoutExpired: + # On timeout, assume it exists to avoid false positives return True + except Exception as e: + # On other errors (command not found, etc.), check if it's a "not found" error + # If we can't determine, assume it doesn't exist to allow cleanup + return False def check_vm_running(self, vm_id: str) -> bool: """ Check if a VM/CT is running and resolve error if so. - Returns True if running and error was resolved. + Also resolves error if VM/CT no longer exists. + Returns True if running/resolved, False otherwise. """ import subprocess try: + vm_exists = False + ct_exists = False + # Check qm status for VMs - result = subprocess.run( + result_vm = subprocess.run( ['qm', 'status', vm_id], capture_output=True, text=True, timeout=2 ) - if result.returncode == 0 and 'running' in result.stdout.lower(): - self.resolve_error(f'vm_{vm_id}', 'VM started') - return True + if result_vm.returncode == 0: + vm_exists = True + if 'running' in result_vm.stdout.lower(): + self.resolve_error(f'vm_{vm_id}', 'VM started') + self.resolve_error(f'vmct_{vm_id}', 'VM started') + return True # Check pct status for containers - result = subprocess.run( + result_ct = subprocess.run( ['pct', 'status', vm_id], capture_output=True, text=True, timeout=2 ) - if result.returncode == 0 and 'running' in result.stdout.lower(): - self.resolve_error(f'ct_{vm_id}', 'Container started') - return True + if result_ct.returncode == 0: + ct_exists = True + if 'running' in result_ct.stdout.lower(): + self.resolve_error(f'ct_{vm_id}', 'Container started') + self.resolve_error(f'vmct_{vm_id}', 'Container started') + return True + + # If neither VM nor CT exists, resolve all related errors + if not vm_exists and not ct_exists: + self.resolve_error(f'vm_{vm_id}', 'VM/CT deleted') + self.resolve_error(f'ct_{vm_id}', 'VM/CT deleted') + self.resolve_error(f'vmct_{vm_id}', 'VM/CT deleted') + return True # Error resolved because resource doesn't exist return False diff --git a/AppImage/scripts/notification_templates.py b/AppImage/scripts/notification_templates.py index 5119ae91..c246d17d 100644 --- a/AppImage/scripts/notification_templates.py +++ b/AppImage/scripts/notification_templates.py @@ -883,7 +883,7 @@ TEMPLATES = { 'default_enabled': True, }, - # ── ProxMenux updates ── + # ── ProxMenux updates ��─ 'proxmenux_update': { 'title': '{hostname}: ProxMenux {new_version} available', 'body': ( diff --git a/AppImage/scripts/startup_grace.py b/AppImage/scripts/startup_grace.py index 33a92df8..eaf65ec2 100644 --- a/AppImage/scripts/startup_grace.py +++ b/AppImage/scripts/startup_grace.py @@ -21,7 +21,7 @@ import time import threading from typing import Set, List, Tuple, Optional -# ─── Configuration ─────────────────────────────────────────────────────────── +# ─── Configuration ───────────────────────���─────────────────────────────────── # Grace period durations (seconds) STARTUP_VM_GRACE_SECONDS = 180 # 3 minutes for VM/CT start aggregation diff --git a/AppImage/scripts/test_real_events.sh b/AppImage/scripts/test_real_events.sh index ad0126c7..8e377f76 100644 --- a/AppImage/scripts/test_real_events.sh +++ b/AppImage/scripts/test_real_events.sh @@ -91,7 +91,7 @@ for h in data.get('history', [])[:$diff]: fi } -# ── Pre-flight checks ──────────────────────���─────────────────── +# ── Pre-flight checks ────────────────────────────────────────── preflight() { header "Pre-flight Checks"