Update notification_events.py

This commit is contained in:
MacRimi
2026-04-02 09:49:54 +02:00
parent 2072264918
commit 3746f356b9
+25 -16
View File
@@ -1351,23 +1351,36 @@ class TaskWatcher:
lines = f.readlines() lines = f.readlines()
# Look for error/warning messages in the log # Look for error/warning messages in the log
# Common patterns: "warning: ...", "error: ...", "failed: ..." # Proxmox uses various patterns: "WARN:", "warning:", "error:", etc.
error_lines = [] error_lines = []
for line in lines: for line in lines:
line_lower = line.lower() line_strip = line.strip()
# Skip status lines at the end (TASK OK, TASK ERROR, etc.) line_lower = line_strip.lower()
if line.startswith('TASK '):
# Skip empty lines and status lines at the end
if not line_strip or line_strip.startswith('TASK '):
continue continue
# Capture warning/error lines
if any(kw in line_lower for kw in ['warning:', 'error:', 'failed', 'unable to', 'cannot', 'exception']): # Capture warning/error lines with various patterns
# Clean up the line # Proxmox uses: "WARN: ...", "warning: ...", "error: ...", "ERROR: ..."
clean_line = line.strip() is_warning_error = any(kw in line_lower for kw in [
if clean_line and len(clean_line) < 200: # Reasonable length 'warn:', 'warning:', 'error:', 'failed', 'failure',
error_lines.append(clean_line) 'unable to', 'cannot', 'exception', 'critical',
'certificate', 'expired', 'expires' # EFI cert warnings
])
# Also check for lines starting with common prefixes
starts_with_prefix = any(line_strip.upper().startswith(p) for p in [
'WARN:', 'WARNING:', 'ERROR:', 'CRITICAL:', 'FATAL:'
])
if is_warning_error or starts_with_prefix:
if len(line_strip) < 300: # Reasonable length
error_lines.append(line_strip)
if error_lines: if error_lines:
# Return the most relevant lines (up to 3) # Return the most relevant lines (up to 5 for better context)
return '; '.join(error_lines[:3]) return '; '.join(error_lines[:5])
return status return status
except Exception as e: except Exception as e:
@@ -1692,7 +1705,6 @@ class TaskWatcher:
'ct_start', 'ct_stop', 'ct_shutdown', 'ct_restart'} 'ct_start', 'ct_stop', 'ct_shutdown', 'ct_restart'}
if event_type in _BACKUP_NOISE and not is_error and not is_warning: if event_type in _BACKUP_NOISE and not is_error and not is_warning:
if self._is_vzdump_active(): if self._is_vzdump_active():
print(f"[TaskWatcher] Suppressed {event_type} for {vmid} - vzdump active")
return return
# Suppress VM/CT stop/shutdown during host shutdown/reboot. # Suppress VM/CT stop/shutdown during host shutdown/reboot.
@@ -1702,7 +1714,6 @@ class TaskWatcher:
_SHUTDOWN_NOISE = {'vm_stop', 'vm_shutdown', 'ct_stop', 'ct_shutdown'} _SHUTDOWN_NOISE = {'vm_stop', 'vm_shutdown', 'ct_stop', 'ct_shutdown'}
if event_type in _SHUTDOWN_NOISE and not is_error and not is_warning: if event_type in _SHUTDOWN_NOISE and not is_error and not is_warning:
if _shared_state.is_host_shutting_down(): if _shared_state.is_host_shutting_down():
print(f"[TaskWatcher] Suppressed {event_type} for {vmid} - host shutdown")
return return
# During startup period, aggregate VM/CT starts into a single message. # During startup period, aggregate VM/CT starts into a single message.
@@ -1712,12 +1723,10 @@ class TaskWatcher:
_STARTUP_EVENTS = {'vm_start', 'ct_start'} _STARTUP_EVENTS = {'vm_start', 'ct_start'}
if event_type in _STARTUP_EVENTS and not is_error and not is_warning: if event_type in _STARTUP_EVENTS and not is_error and not is_warning:
if _shared_state.is_startup_period(): if _shared_state.is_startup_period():
print(f"[TaskWatcher] Suppressed {event_type} for {vmid} - startup period active")
vm_type = 'ct' if event_type == 'ct_start' else 'vm' vm_type = 'ct' if event_type == 'ct_start' else 'vm'
_shared_state.add_startup_vm(vmid, vmname or f'ID {vmid}', vm_type) _shared_state.add_startup_vm(vmid, vmname or f'ID {vmid}', vm_type)
return return
print(f"[TaskWatcher] Emitting event: {event_type}, severity={severity}, vmid={vmid}, vmname={vmname}")
self._queue.put(NotificationEvent( self._queue.put(NotificationEvent(
event_type, severity, data, source='tasks', event_type, severity, data, source='tasks',
entity=entity, entity_id=vmid, entity=entity, entity_id=vmid,