update health_persistence.py

This commit is contained in:
MacRimi
2026-03-31 20:55:17 +02:00
parent 65dfb9103f
commit 5138b2f1d5
5 changed files with 36 additions and 15 deletions
@@ -855,7 +855,7 @@ def proxmox_webhook():
resp.headers['Retry-After'] = '60' resp.headers['Retry-After'] = '60'
return resp, 429 return resp, 429
# ─ Layers 2-5: Remote-only checks ── # ─ Layers 2-5: Remote-only checks ──
if not is_localhost: if not is_localhost:
# Layer 2: Shared secret # Layer 2: Shared secret
try: try:
+32 -11
View File
@@ -1182,41 +1182,62 @@ class HealthPersistence:
return True return True
return False return False
except Exception: except subprocess.TimeoutExpired:
# On error, assume it exists to avoid false positives # On timeout, assume it exists to avoid false positives
return True 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: def check_vm_running(self, vm_id: str) -> bool:
""" """
Check if a VM/CT is running and resolve error if so. 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 import subprocess
try: try:
vm_exists = False
ct_exists = False
# Check qm status for VMs # Check qm status for VMs
result = subprocess.run( result_vm = subprocess.run(
['qm', 'status', vm_id], ['qm', 'status', vm_id],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=2 timeout=2
) )
if result.returncode == 0 and 'running' in result.stdout.lower(): if result_vm.returncode == 0:
self.resolve_error(f'vm_{vm_id}', 'VM started') vm_exists = True
return 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 # Check pct status for containers
result = subprocess.run( result_ct = subprocess.run(
['pct', 'status', vm_id], ['pct', 'status', vm_id],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=2 timeout=2
) )
if result.returncode == 0 and 'running' in result.stdout.lower(): if result_ct.returncode == 0:
self.resolve_error(f'ct_{vm_id}', 'Container started') ct_exists = True
return 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 return False
+1 -1
View File
@@ -883,7 +883,7 @@ TEMPLATES = {
'default_enabled': True, 'default_enabled': True,
}, },
# ── ProxMenux updates # ── ProxMenux updates
'proxmenux_update': { 'proxmenux_update': {
'title': '{hostname}: ProxMenux {new_version} available', 'title': '{hostname}: ProxMenux {new_version} available',
'body': ( 'body': (
+1 -1
View File
@@ -21,7 +21,7 @@ import time
import threading import threading
from typing import Set, List, Tuple, Optional from typing import Set, List, Tuple, Optional
# ─── Configuration ────────────────────────────────────────────────────────── # ─── Configuration ──────────────────────────────────────────────────────────
# Grace period durations (seconds) # Grace period durations (seconds)
STARTUP_VM_GRACE_SECONDS = 180 # 3 minutes for VM/CT start aggregation STARTUP_VM_GRACE_SECONDS = 180 # 3 minutes for VM/CT start aggregation
+1 -1
View File
@@ -91,7 +91,7 @@ for h in data.get('history', [])[:$diff]:
fi fi
} }
# ── Pre-flight checks ───────────────────────────────────────── # ── Pre-flight checks ─────────────────────────────────────────
preflight() { preflight() {
header "Pre-flight Checks" header "Pre-flight Checks"