Check hard drive health using S.M.A.R.T.

This commit is contained in:
Jan Schulz-Hofen
2020-02-20 23:28:41 +01:00
parent 30c2c60f59
commit 97abacccc3
2 changed files with 39 additions and 0 deletions
+22
View File
@@ -165,6 +165,7 @@ def run_system_checks(rounded_values, env, output):
check_miab_version(env, output)
check_system_aliases(env, output)
check_free_disk_space(rounded_values, env, output)
check_smart_status(env, output)
check_free_memory(rounded_values, env, output)
def check_ufw(env, output):
@@ -250,6 +251,27 @@ def check_free_disk_space(rounded_values, env, output):
if rounded_values: disk_msg = "The disk has less than 15% free space."
output.print_error(disk_msg)
def check_smart_status(env, output):
devices = shell('check_output', ['smartctl', '--scan-open'])
for device in devices.splitlines():
device = device.split()[0]
info = shell('check_output', ['smartctl', '-i', device])
if 'SMART support is: Available' in info:
if 'SMART support is: Enabled' in info:
code, health = shell('check_output', ['smartctl', '-H', device, '--quietmode=errorsonly'], trap=True)
if code == 0:
output.print_ok('Disk %s passed all S.M.A.R.T. checks and seems healthy.' % device)
else:
output.print_error('Disk %s failed the S.M.A.R.T health check. Consider replacing the hard drive. Detailed information:' % device)
output.print_line("")
for line in health.split('=== START OF READ SMART DATA SECTION ===')[1].splitlines():
output.print_line(line)
else:
output.print_warning('Disk %s supports S.M.A.R.T, but it is disabled. You should activate it using \'sudo smartctl -s on %s\'.' % (device, device))
else:
output.print_ok('Disk %s does not support S.M.A.R.T. Health checks are skipped.' % device)
def check_free_memory(rounded_values, env, output):
# Check free memory.
percent_free = 100 - psutil.virtual_memory().percent