Drive info in description

This commit is contained in:
2025-03-03 19:37:33 -05:00
parent 2be4f9072c
commit 8980022959

View File

@ -132,6 +132,43 @@ class SystemHealthMonitor:
return health_report
def _get_drive_details(self, device: str) -> Dict[str, str]:
"""
Get detailed drive information using smartctl
"""
drive_details = {
'model': None,
'serial': None,
'capacity': None,
'firmware': None,
'type': None # SSD or HDD
}
try:
result = subprocess.run(
['smartctl', '-i', device],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
for line in result.stdout.split('\n'):
if 'Device Model' in line:
drive_details['model'] = line.split(':')[1].strip()
elif 'Serial Number' in line:
drive_details['serial'] = line.split(':')[1].strip()
elif 'User Capacity' in line:
drive_details['capacity'] = line.split('[')[1].split(']')[0]
elif 'Firmware Version' in line:
drive_details['firmware'] = line.split(':')[1].strip()
elif 'Rotation Rate' in line:
drive_details['type'] = 'SSD' if 'Solid State Device' in line else 'HDD'
except Exception as e:
logger.debug(f"Error getting drive details: {e}")
return drive_details
def _generate_detailed_description(self, issue: str, health_report: Dict[str, Any]) -> str:
# Keep existing banner and initial description
banner = """
@ -331,6 +368,17 @@ class SystemHealthMonitor:
- Possible drive failure!
"""
if "Drive" in issue:
device = re.search(r'/dev/[a-zA-Z0-9]+', issue).group(0)
drive_details = self._get_drive_details(device)
description += "\n=== Drive Details ===\n"
description += f"Device: {device}\n"
description += f"Model: {drive_details['model']}\n"
description += f"Serial Number: {drive_details['serial']}\n"
description += f"Capacity: {drive_details['capacity']}\n"
description += f"Firmware: {drive_details['firmware']}\n"
description += f"Type: {drive_details['type']}\n"
if "Temperature" in issue:
description += """
High drive temperatures can:
@ -366,7 +414,6 @@ class SystemHealthMonitor:
- Management access
"""
# Keep existing detailed metrics section
if "Disk" in issue:
for partition in health_report.get('drives_health', {}).get('drives', []):
if partition.get('mountpoint') in issue:
@ -398,7 +445,12 @@ class SystemHealthMonitor:
issue_type = self.TICKET_TEMPLATES['DEFAULT_ISSUE_TYPE']
scope = self.TICKET_TEMPLATES['SCOPE_SINGLE']
# Priority and type assignment logic remains the same...
drive_size = ""
if "Drive" in issue:
device = re.search(r'/dev/[a-zA-Z0-9]+', issue).group(0)
drive_details = self._get_drive_details(device)
if drive_details['capacity']:
drive_size = f"[{drive_details['capacity']}] "
ticket_title = f"[{hostname}]{action_type}{hardware_type} {issue} {scope}{environment}{ticket_type}"
description = self._generate_detailed_description(issue, health_report)
@ -985,8 +1037,6 @@ class SystemHealthMonitor:
}
def main():
try:
# Argument parser for CLI options
parser = argparse.ArgumentParser(description="System Health Monitor")
parser.add_argument(
"--dry-run",
@ -995,35 +1045,11 @@ def main():
)
args = parser.parse_args()
# Parse command-line arguments or read from configuration file
ticket_api_url = "http://10.10.10.45/create_ticket_api.php"
# Instantiate the SystemHealthMonitor class
monitor = SystemHealthMonitor(
ticket_api_url=SystemHealthMonitor.CONFIG['TICKET_API_URL'],
dry_run=args.dry_run
)
# Run the health checks
monitor.run()
# Check network health synchronously
network_health = monitor._check_network_status()
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")
sys.exit(1)
if __name__ == "__main__":
# Argument parser for CLI options
parser = argparse.ArgumentParser(description="System Health Monitor")
parser.add_argument(
"--dry-run",
action="store_true",
help="Enable dry-run mode (simulate ticket creation without actual API calls)."
)
args = parser.parse_args()
# Set dry-run mode if specified
dry_run_mode = args.dry_run
main()