mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-09-15 00:48:00 +02:00
Check hard drive health using S.M.A.R.T.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user