Updated drive ticket creation

This commit is contained in:
2025-05-12 15:47:14 -04:00
parent 20f51e0b25
commit af1121e3d9

View File

@ -467,9 +467,12 @@ class SystemHealthMonitor:
- Possible drive failure! - Possible drive failure!
""" """
if "Drive" in issue: if "Drive" in issue and "/dev/" in issue:
try:
device = re.search(r'/dev/[a-zA-Z0-9]+', issue).group(0) if '/dev/' in issue else None device = re.search(r'/dev/[a-zA-Z0-9]+', issue).group(0) if '/dev/' in issue else None
drive_info = next((d for d in health_report['drives_health']['drives'] if d['device'] == device), None) drive_info = next((d for d in health_report['drives_health']['drives'] if d['device'] == device), None)
if drive_info:
drive_details = self._get_drive_details(device) drive_details = self._get_drive_details(device)
smart_data = { smart_data = {
@ -483,21 +486,21 @@ class SystemHealthMonitor:
age = f"{int(power_on_hours/24/365) if isinstance(power_on_hours, (int, float)) else 'N/A'} years" if power_on_hours != 'N/A' else 'N/A' age = f"{int(power_on_hours/24/365) if isinstance(power_on_hours, (int, float)) else 'N/A'} years" if power_on_hours != 'N/A' else 'N/A'
description += """ description += """
┏━ DRIVE SPECIFICATIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━ DRIVE SPECIFICATIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Device Path │ {:<60} ┃ Device Path │ {:<60}
┃ Model │ {:<60} ┃ Model │ {:<60}
┃ Serial │ {:<60} ┃ Serial │ {:<60}
┃ Capacity │ {:<60} ┃ Capacity │ {:<60}
┃ Type │ {:<60} ┃ Type │ {:<60}
┃ Firmware │ {:<60} ┃ Firmware │ {:<60}
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
""".format( """.format(
device, device,
drive_details['model'], drive_details.get('model', 'N/A'),
drive_details['serial'], drive_details.get('serial', 'N/A'),
drive_details['capacity'], drive_details.get('capacity', 'N/A'),
drive_details['type'], drive_details.get('type', 'N/A'),
drive_details['firmware'] drive_details.get('firmware', 'N/A')
) )
if drive_info: if drive_info:
@ -509,59 +512,57 @@ class SystemHealthMonitor:
} }
description += """ description += """
┏━ DRIVE TIMELINE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━ DRIVE TIMELINE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Power-On Hours │ {:<56} ┃ Power-On Hours │ {:<56}
┃ Last SMART Test │ {:<56} ┃ Last SMART Test │ {:<56}
┃ Drive Age │ {:<56} ┃ Drive Age │ {:<56}
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
""".format( """.format(
f"{power_on_hours} hours" if power_on_hours != 'N/A' else 'N/A', f"{power_on_hours} hours" if power_on_hours != 'N/A' else 'N/A',
last_test_date, last_test_date,
age age
) )
for drive in health_report.get('drives_health', {}).get('drives', []):
if drive['device'] == device:
description += """ description += """
┏━ SMART STATUS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┏━ SMART STATUS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Status │ {:<60} ┃ Status │ {:<60}
┃ Temperature │ {:<60} ┃ Temperature │ {:<60}
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
""".format( """.format(
drive['smart_status'], drive_info.get('smart_status', 'N/A'),
f"{drive.get('temperature')}°C" if drive.get('temperature') else 'N/A' f"{drive_info.get('temperature')}°C" if drive_info.get('temperature') else 'N/A'
) )
if drive.get('smart_attributes'): if drive_info.get('smart_attributes'):
description += "\n┏━ SMART ATTRIBUTES " + "" * 48 + "\n" description += "\n┏━ SMART ATTRIBUTES " + "" * 48 + "\n"
for attr, value in drive['smart_attributes'].items(): for attr, value in drive_info['smart_attributes'].items():
description += "{:<25}{:<37}\n".format( description += "{:<25}{:<37}\n".format(
attr.replace('_', ' '), value attr.replace('_', ' '), value
) )
description += "" + "" * 71 + "\n" description += "" + "" * 71 + "\n"
if drive.get('partitions'): if drive_info.get('partitions'):
for partition in drive['partitions']: for partition in drive_info['partitions']:
usage_percent = partition['usage_percent'] usage_percent = partition.get('usage_percent', 0)
blocks = int(usage_percent / 5) # 20 blocks total = 100% blocks = int(usage_percent / 5) # 20 blocks total = 100%
usage_meter = '' * blocks + '' * (20 - blocks) usage_meter = '' * blocks + '' * (20 - blocks)
description += """ description += """
┏━ PARTITION [{:<60}] ━┓ ┏━ PARTITION [{:<60}] ━┓
┃ Filesystem │ {:<60} ┃ Filesystem │ {:<60}
┃ Usage Meter │ [{:<58}] ┃ ┃ Usage Meter │ [{:<58}] ┃
┃ Total Space │ {:<60} ┃ Total Space │ {:<60}
┃ Used Space │ {:<60} ┃ Used Space │ {:<60}
┃ Free Space │ {:<60} ┃ Free Space │ {:<60}
┃ Usage │ {:<60} ┃ Usage │ {:<60}
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
""".format( """.format(
partition['mountpoint'], partition.get('mountpoint', 'N/A'),
partition['fstype'], partition.get('fstype', 'N/A'),
usage_meter, usage_meter,
partition['total_space'], partition.get('total_space', 'N/A'),
partition['used_space'], partition.get('used_space', 'N/A'),
partition['free_space'], partition.get('free_space', 'N/A'),
f"{usage_percent}%" f"{usage_percent}%"
) )
@ -571,6 +572,8 @@ class SystemHealthMonitor:
for issue in firmware_info['known_issues']: for issue in firmware_info['known_issues']:
description += "┃ ⚠ {:<67}\n".format(issue) description += "┃ ⚠ {:<67}\n".format(issue)
description += "" + "" * 71 + "\n" description += "" + "" * 71 + "\n"
except Exception as e:
description += f"\nError generating drive details: {str(e)}\n"
if "Temperature" in issue: if "Temperature" in issue:
description += """ description += """