truenas / py-SMART

Wrapper for smartctl (smartmontools)
GNU Lesser General Public License v2.1
79 stars 35 forks source link

Feature request: HDD in STANDBY mode #82

Open petersulyok opened 8 months ago

petersulyok commented 8 months ago

Hi,

I'm looking for a solution for a situation when I'm checking the state of a hard disk in STANDBY mode (it spun down) and I don't want to wake it up. The typical smartctl output is the following:

$ sudo smartctl -n standby --all /dev/sda
smartctl 7.3 2022-02-28 r5338 [x86_64-linux-6.5.0-0.deb12.4-amd64] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

Device is in STANDBY mode, exit(2)

When I use pySMART in this context I got the following output:

Python 3.12.2 (main, Feb 17 2024, 07:08:59) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pySMART import *
>>> SMARTCTL.sudo=True
>>> SMARTCTL.options=["-n", "standby"]
>>> SMARTCTL.smartctl_path="/usr/sbin/smartctl"
>>> d=Device("sda")
>>> d
<SAT device on /dev/sda mod:None sn:None>

How can I detect in Device() class if the HDD is in STANDBY mode and the rest of the class is empty? In my mind one or more of the following suggestions would help:

Any recommendation for this? Thanks in advance. Peter

petersulyok commented 7 months ago

Hi @ralequi,

As a temporary workaround I use this code to detect STANDBY state of a HDD:

    ...
    rv.standby_mode = False
    SMARTCTL.options = []
    SMARTCTL.smartctl_path = smartctl_path

    # If sudo command should be used
    if sudo:
        SMARTCTL.sudo = True
    else:
        SMARTCTL.sudo = False

    # If no check should be applied in standby power mode of an HDD
    if nocheck:
        SMARTCTL.add_options(["-n", "standby"])

    # Check if `smartctl` can be executed.
    output = SMARTCTL.info(self.__path)
    if not output:
        return None

    # Check if the disk is in STANDBY mode
    if "Device is in STANDBY mode" in output[3]:
        rv.standby_mode = True
        return rv

    # Get SMART data from pySMART.
    sd = Device(self.__path)
    ...

Please confirm this approach or suggest a better one. Thanks.

ralequi commented 7 months ago

I've forgotten about this issue.

Let me try some scenarios on my lab.

I would like to check if -n standby is a requirement and how to known when it is