truenas / py-SMART

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

DeviceList().all_attributes() always sends output to stdout #80

Closed khorton closed 9 months ago

khorton commented 9 months ago

Describe the bug DeviceList().all_attributes() always sends output to stdout. No data is returned to the user. This greatly complicates using all_attributes in a script.

% python3 Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import pySMART devices = pySMART.DeviceList() atts = devices[0].all_attributes() # Note unexpected output to stdout ID# ATTRIBUTE_NAME CUR WST THR TYPE UPDATED WHEN_FAIL RAW 1 Raw_Read_Error_Rate 200 200 51 Pre-fail Always - 0 3 Spin_Up_Time 178 177 21 Pre-fail Always - 8075 4 Start_Stop_Count 100 100 0 Old_age Always - 172 5 Reallocated_Sector_Ct 200 200 140 Pre-fail Always - 0 7 Seek_Error_Rate 200 200 0 Old_age Always - 0 9 Power_On_Hours 026 26 0 Old_age Always - 54078 10 Spin_Retry_Count 100 100 0 Old_age Always - 0 11 Calibration_Retry_Count 100 100 0 Old_age Always - 0 12 Power_Cycle_Count 100 100 0 Old_age Always - 172 192 Power-Off_Retract_Count 200 200 0 Old_age Always - 159 193 Load_Cycle_Count 200 200 0 Old_age Always - 654 194 Temperature_Celsius 115 109 0 Old_age Always - 37 196 Reallocated_Event_Count 200 200 0 Old_age Always - 0 197 Current_Pending_Sector 200 200 0 Old_age Always - 0 198 Offline_Uncorrectable 100 253 0 Old_age Offline - 0 199 UDMA_CRC_Error_Count 200 200 0 Old_age Always - 0 200 Multi_Zone_Error_Rate 200 200 0 Old_age Offline - 0 atts # Note that the attributes were not copied to ants

Raw outputs % smartctl --scan-open /dev/sda -d sat # /dev/sda [SAT], ATA device /dev/sdb -d sat # /dev/sdb [SAT], ATA device /dev/sdc -d sat # /dev/sdc [SAT], ATA device /dev/sdd -d sat # /dev/sdd [SAT], ATA device /dev/sde -d sat # /dev/sde [SAT], ATA device /dev/sdf -d sat # /dev/sdf [SAT], ATA device /dev/sdg -d sat # /dev/sdg [SAT], ATA device /dev/sdh -d sat # /dev/sdh [SAT], ATA device /dev/sdi -d sat # /dev/sdi [SAT], ATA device

% smartctl --all /dev/sda smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-92-generic] (local build) Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION === Model Family: Western Digital Red Device Model: WDC WD40EFRX-68WT0N0 Serial Number: WD-WCC4E0SAKENS LU WWN Device Id: 5 0014ee 2b7d00d8a Firmware Version: 82.00A82 User Capacity: 4,000,787,030,016 bytes [4.00 TB] Sector Sizes: 512 bytes logical, 4096 bytes physical Rotation Rate: 5400 rpm Device is: In smartctl database [for details use: -P show] ATA Version is: ACS-2 (minor revision not indicated) SATA Version is: SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s) Local Time is: Tue Jan 30 17:44:48 2024 CST SMART support is: Available - device has SMART capability. SMART support is: Enabled

=== START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED

General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled. Self-test execution status: ( 0) The previous self-test routine completed without error or no self-test has ever been run. Total time to complete Offline data collection: (52980) seconds. Offline data collection capabilities: (0x7b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. Conveyance Self-test supported. Selective Self-test supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x01) Error logging supported. General Purpose Logging supported. Short self-test routine recommended polling time: ( 2) minutes. Extended self-test routine recommended polling time: ( 530) minutes. Conveyance self-test routine recommended polling time: ( 5) minutes. SCT capabilities: (0x703d) SCT Status supported. SCT Error Recovery Control supported. SCT Feature Control supported. SCT Data Table supported.

SMART Attributes Data Structure revision number: 16 Vendor Specific SMART Attributes with Thresholds: ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 1 Raw_Read_Error_Rate 0x002f 200 200 051 Pre-fail Always - 0 3 Spin_Up_Time 0x0027 178 177 021 Pre-fail Always - 8075 4 Start_Stop_Count 0x0032 100 100 000 Old_age Always - 172 5 Reallocated_Sector_Ct 0x0033 200 200 140 Pre-fail Always - 0 7 Seek_Error_Rate 0x002e 200 200 000 Old_age Always - 0 9 Power_On_Hours 0x0032 026 026 000 Old_age Always - 54078 10 Spin_Retry_Count 0x0032 100 100 000 Old_age Always - 0 11 Calibration_Retry_Count 0x0032 100 100 000 Old_age Always - 0 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 172 192 Power-Off_Retract_Count 0x0032 200 200 000 Old_age Always - 159 193 Load_Cycle_Count 0x0032 200 200 000 Old_age Always - 654 194 Temperature_Celsius 0x0022 115 109 000 Old_age Always - 37 196 Reallocated_Event_Count 0x0032 200 200 000 Old_age Always - 0 197 Current_Pending_Sector 0x0032 200 200 000 Old_age Always - 0 198 Offline_Uncorrectable 0x0030 100 253 000 Old_age Offline - 0 199 UDMA_CRC_Error_Count 0x0032 200 200 000 Old_age Always - 0 200 Multi_Zone_Error_Rate 0x0008 200 200 000 Old_age Offline - 0

SMART Error Log Version: 1 No Errors Logged

SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error

1 Short offline Completed without error 00% 54056 -

2 Extended offline Completed without error 00% 54044 -

3 Short offline Completed without error 00% 54033 -

4 Short offline Completed without error 00% 54032 -

5 Short offline Completed without error 00% 53948 -

6 Extended offline Completed without error 00% 53768 -

7 Short offline Completed without error 00% 53652 -

8 Short offline Completed without error 00% 53532 -

9 Extended offline Completed without error 00% 53408 -

10 Short offline Completed without error 00% 53268 -

11 Short offline Completed without error 00% 53149 -

12 Extended offline Completed without error 00% 53024 -

13 Short offline Completed without error 00% 52909 -

14 Short offline Completed without error 00% 52789 -

15 Extended offline Completed without error 00% 52665 -

16 Short offline Completed without error 00% 52549 -

17 Short offline Completed without error 00% 52429 -

18 Extended offline Completed without error 00% 52305 -

19 Short offline Completed without error 00% 52189 -

20 Short offline Completed without error 00% 52070 -

21 Extended offline Completed without error 00% 51944 -

SMART Selective self-test log data structure revision number 1 SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS 1 0 0 Not_testing 2 0 0 Not_testing 3 0 0 Not_testing 4 0 0 Not_testing 5 0 0 Not_testing Selective self-test flags (0x0): After scanning selected spans, do NOT read-scan remainder of disk. If Selective self-test is pending on power-up, resume after 0 minute delay.

Environmental setup: % smartctl --version smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-92-generic] (local build)

% pip3 list | grep pySMART pySMART 1.3.0 Additional context Add any other context about the problem here.

ralequi commented 9 months ago

Hi @khorton

Thanks for your report. First of all, let me excuse myself, didn't notice it until now.

According to the method:


    def all_attributes(self, print_fn=print):
        """
        Prints the entire SMART attribute table, in a format similar to
        the output of smartctl.
        allows usage of custom print function via parameter print_fn by default uses print
        """        

Have you tried passing a print_fn function that actually prints in another file or whatever?

Just to be clear, are you sure that what you want is to PRINT the results instead of using them in some other way?

khorton commented 9 months ago

Thanks for the info. You are correct to assume that what I really wanted was a way to parse the data so I could use it in a script. I have not yet found the Docs, so I was not aware of the print_fn function. A more descriptive hint on where to find the py-SMART docs would be appreciated. I looked in the release tarball, and found nothing.

ralequi commented 9 months ago

Hi @khorton ,

There is no doc associated but the code itself. The DeviceList is exactly that, an object that simulates a list of Devices -> https://github.com/truenas/py-SMART/blob/master/pySMART/device_list.py The Device object is defined in -> https://github.com/truenas/py-SMART/blob/master/pySMART/device.py

You can try to read some shared values on the object, but what you might found should vary a lot depending on the device hw you are looking for. For that reason, I recommend to check the if_attributes property instead. SCSI devices are not yet ported to if_attributes, so it would be still stored in the diagnostics property.

Much work left to do, not so much spare time.

Glad to help with other questions