mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-05 20:03:48 +00:00
update health_persistence.py
This commit is contained in:
@@ -855,7 +855,7 @@ def proxmox_webhook():
|
||||
resp.headers['Retry-After'] = '60'
|
||||
return resp, 429
|
||||
|
||||
# <EFBFBD><EFBFBD>─ Layers 2-5: Remote-only checks ──
|
||||
# ── Layers 2-5: Remote-only checks ──
|
||||
if not is_localhost:
|
||||
# Layer 2: Shared secret
|
||||
try:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -883,7 +883,7 @@ TEMPLATES = {
|
||||
'default_enabled': True,
|
||||
},
|
||||
|
||||
# ── ProxMenux updates ──
|
||||
# ── ProxMenux updates <EFBFBD><EFBFBD>─
|
||||
'proxmenux_update': {
|
||||
'title': '{hostname}: ProxMenux {new_version} available',
|
||||
'body': (
|
||||
|
||||
@@ -21,7 +21,7 @@ import time
|
||||
import threading
|
||||
from typing import Set, List, Tuple, Optional
|
||||
|
||||
# ─── Configuration ───────────────────────────────────────────────────────────
|
||||
# ─── Configuration ───────────────────────<EFBFBD><EFBFBD><EFBFBD>───────────────────────────────────
|
||||
|
||||
# Grace period durations (seconds)
|
||||
STARTUP_VM_GRACE_SECONDS = 180 # 3 minutes for VM/CT start aggregation
|
||||
|
||||
@@ -91,7 +91,7 @@ for h in data.get('history', [])[:$diff]:
|
||||
fi
|
||||
}
|
||||
|
||||
# ── Pre-flight checks ──────────────────────<EFBFBD><EFBFBD><EFBFBD>───────────────────
|
||||
# ── Pre-flight checks ──────────────────────────────────────────
|
||||
preflight() {
|
||||
header "Pre-flight Checks"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user