fix(monitor): honour storage exclusions in the PVE storage capacity alert

This commit is contained in:
MacRimi
2026-09-29 20:56:02 +02:00
parent 438cb935d0
commit f421ac1cb1
3 changed files with 27 additions and 1 deletions
+3
View File
@@ -6616,6 +6616,7 @@ class HealthMonitor:
warn_pct, crit_pct = self._read_capacity_thresholds("pve_storage")
available_storages = storage_status.get('available', []) or []
excluded_names = health_persistence.get_excluded_storage_names('health')
checks: Dict[str, Dict[str, Any]] = {}
critical_labels: list[str] = []
warning_labels: list[str] = []
@@ -6631,6 +6632,8 @@ class HealthMonitor:
continue
pct = (used / total) * 100
name = st.get('name', 'unknown')
if name in excluded_names:
continue
label = f'{name} ({stype})'
entry = {
'detail': f'{pct:.1f}% used',
+2 -1
View File
@@ -1277,7 +1277,8 @@ class NotificationManager:
# Check storage exclusions for storage-related events.
# If the storage is excluded from notifications, suppress the event entirely.
_STORAGE_EVENTS = {'storage_unavailable', 'storage_low_space', 'storage_warning', 'storage_error'}
_STORAGE_EVENTS = {'storage_unavailable', 'storage_low_space', 'storage_warning', 'storage_error',
'pve_storage_full'}
if event.event_type in _STORAGE_EVENTS:
storage_name = event.data.get('storage_name') or event.data.get('name')
if storage_name:
@@ -45,6 +45,7 @@ class StorageUsageDetail(unittest.TestCase):
persistence = health_monitor.health_persistence
with patch.dict(sys.modules, {'proxmox_storage_monitor': module}), \
patch.object(health_monitor, 'PROXMOX_STORAGE_AVAILABLE', True), \
patch.object(persistence, 'get_excluded_storage_names', return_value=set()), \
patch.object(persistence, 'is_error_acknowledged', return_value=False), \
patch.object(persistence, 'record_error'), \
patch.object(persistence, 'get_active_errors', return_value=[]):
@@ -52,6 +53,27 @@ class StorageUsageDetail(unittest.TestCase):
entry = result['checks']['PBS-Cloud (pbs)']
self.assertEqual((entry['status'], entry['detail']), ('WARNING', '92.4% used'))
def test_a_storage_excluded_from_health_is_not_checked(self):
# Excluded in Health -> Exclusions, it raises nothing and its earlier
# error is cleared on the next cycle.
monitor = health_monitor.HealthMonitor.__new__(health_monitor.HealthMonitor)
monitor._read_capacity_thresholds = lambda section: (85, 95)
status = {'available': [{'name': 'Pluton', 'type': 'pbs', 'total': 1000, 'used': 860}]}
module = MagicMock()
module.proxmox_storage_monitor.get_storage_status.return_value = status
persistence = health_monitor.health_persistence
with patch.dict(sys.modules, {'proxmox_storage_monitor': module}), \
patch.object(health_monitor, 'PROXMOX_STORAGE_AVAILABLE', True), \
patch.object(persistence, 'get_excluded_storage_names', return_value={'Pluton'}), \
patch.object(persistence, 'record_error') as record, \
patch.object(persistence, 'clear_error') as clear, \
patch.object(persistence, 'get_active_errors',
return_value=[{'error_key': 'pve_storage_full_Pluton'}]):
result = monitor._check_pve_storage_capacity()
self.assertIsNone(result)
record.assert_not_called()
clear.assert_called_once_with('pve_storage_full_Pluton')
class FstrimUnsupportedDevices(unittest.TestCase):
def run_with(self, journal):