Changed dictionary access for single scope

This commit is contained in:
2025-03-09 17:48:04 -04:00
parent ed5b0cab52
commit 0db590570d

View File

@ -633,7 +633,7 @@ class SystemHealthMonitor:
priority = self.PRIORITIES['MEDIUM'] priority = self.PRIORITIES['MEDIUM']
category = self.TICKET_TEMPLATES['DEFAULT_CATEGORY'] category = self.TICKET_TEMPLATES['DEFAULT_CATEGORY']
issue_type = self.TICKET_TEMPLATES['DEFAULT_ISSUE_TYPE'] issue_type = self.TICKET_TEMPLATES['DEFAULT_ISSUE_TYPE']
scope = self.TICKET_TEMPLATES['SCOPE_SINGLE'] scope = self.TICKET_TEMPLATES['SCOPE']['SINGLE_NODE']
drive_size = "" drive_size = ""
if "Drive" in issue: if "Drive" in issue:
@ -1381,46 +1381,47 @@ class SystemHealthMonitor:
try: try:
parts = fs_line.split() parts = fs_line.split()
if len(parts) >= 6: if len(parts) >= 6:
if parts[5] and not self._is_excluded_mount(parts[5]): if any(re.match(pattern, parts[5]) for pattern in self.CONFIG['EXCLUDED_PATTERNS']) or \
parts[5] in self.CONFIG['EXCLUDED_MOUNTS']:
continue
# Convert size strings to comparable values
total = parts[2]
used = parts[3]
avail = parts[4]
# Convert size strings to comparable values # Calculate usage percentage
total = parts[2] total_bytes = self._convert_size_to_bytes(total)
used = parts[3] used_bytes = self._convert_size_to_bytes(used)
avail = parts[4] usage_percent = int((used_bytes / total_bytes) * 100)
# Calculate usage percentage filesystem = {
total_bytes = self._convert_size_to_bytes(total) 'mountpoint': parts[5],
used_bytes = self._convert_size_to_bytes(used) 'total': total,
usage_percent = int((used_bytes / total_bytes) * 100) 'used': used,
'available': avail,
'usage_percent': usage_percent
}
filesystem = { if self.dry_run:
'mountpoint': parts[5], logger.debug(f"Container {vmid} filesystem details:")
'total': total, logger.debug(f" Mountpoint: {filesystem['mountpoint']}")
'used': used, logger.debug(f" Usage: {used}/{total} ({usage_percent}%)")
'available': avail,
'usage_percent': usage_percent
}
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
lxc_health['status'] = 'CRITICAL'
issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}"
lxc_health['issues'].append(issue)
if self.dry_run: if self.dry_run:
logger.debug(f"Container {vmid} filesystem details:") logger.debug(f"Critical issue detected: {issue}")
logger.debug(f" Mountpoint: {filesystem['mountpoint']}") elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
logger.debug(f" Usage: {used}/{total} ({usage_percent}%)") if lxc_health['status'] != 'CRITICAL':
lxc_health['status'] = 'WARNING'
issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}"
lxc_health['issues'].append(issue)
if self.dry_run:
logger.debug(f"Warning issue detected: {issue}")
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: container_info['filesystems'].append(filesystem)
lxc_health['status'] = 'CRITICAL'
issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}"
lxc_health['issues'].append(issue)
if self.dry_run:
logger.debug(f"Critical issue detected: {issue}")
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
if lxc_health['status'] != 'CRITICAL':
lxc_health['status'] = 'WARNING'
issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}"
lxc_health['issues'].append(issue)
if self.dry_run:
logger.debug(f"Warning issue detected: {issue}")
container_info['filesystems'].append(filesystem)
except Exception as e: except Exception as e:
if self.dry_run: if self.dry_run:
logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}") logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")