Browse Source

Fixed a bug where NOTICEs where not shown in the command line output (https://github.com/ercpe/smart-check/issues/1). Thanks to Patrick Kuijvenhoven for reporting this issue.

An exit code of 1 for NOTICEs (like WARNINGS) can now be enabled with the -n / --notices-are-warnings command line argument.
tags/0.3.1
Johann Schmitz 3 years ago
parent
commit
c43ba3114e
3 changed files with 113 additions and 1 deletions
  1. 8
    1
      smartcheck/__main__.py
  2. 13
    0
      tests/check.py
  3. 92
    0
      tests/samples/hitachi-HDS723020BLA642.txt

+ 8
- 1
smartcheck/__main__.py View File

@@ -45,6 +45,8 @@ if __name__ == "__main__":
parser.add_argument('-f', '--file', help="Use S.M.A.R.T. report from file instead of calling smartctl (Use - to read from stdin)")

parser.add_argument('-x', '--exclude-notices', help='Do not report NOTICE warnings (default: %(default)s)', action='store_true', default=False)
parser.add_argument('-n', '--notices-are-warnings', help='Exit with status code 1 on NOTICEs too (default: %(default)s)', action='store_true', default=False)

parser.add_argument('--ignore-attributes', help='Ignore this S.M.A.R.T. attributes (id or name)', nargs='*')
parser.add_argument('-v', '--verbose', help='Verbose messages', action='store_true', default=False)
parser.add_argument('--debug', help="Print debug messages", action="store_true", default=False)
@@ -90,6 +92,11 @@ if __name__ == "__main__":
if attribute_errors:
msg = ', '.join([ae.long_message if args.verbose else ae.short_message for ae in attribute_errors.values()])

# set the exit code of NOTICEs to WARNINGs if (-n / --notices-are-warnings) is set
if args.notices_are_warnings and \
any((ae.level == AttributeWarning.Notice for ae in attribute_errors.values())):
exit_code = 1

if any((ae.level == AttributeWarning.Warning for ae in attribute_errors.values())):
exit_code = 1
if any((ae.level == AttributeWarning.Critical for ae in attribute_errors.values())):
@@ -103,7 +110,7 @@ if __name__ == "__main__":
msg = (msg.strip() + '; %s ATA errors found' % check.ata_error_count).lstrip(';').strip()
exit_code = 2

if not exit_code:
if not exit_code and not msg:
msg = "S.M.A.R.T. data OK"

msg = "%s: %s" % (check.device_model, msg)

+ 13
- 0
tests/check.py View File

@@ -167,3 +167,16 @@ ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_
assert failed_id == 197
assert failed_name == "Current_Pending_Sector"
assert int(failed_attribute.value) == 24

def test_notice_warnings(self):
with open(os.path.join(samples_path, 'hitachi-HDS723020BLA642.txt')) as f:
check = SMARTCheck(f)
self.assertFalse(check.check())
failed = check.check_attributes()
self.assertEqual(len(failed), 1)
self.assertEqual(failed, {
(5, 'Reallocated_Sector_Ct'): AttributeWarning(AttributeWarning.Notice, 'Reallocated_Sector_Ct', '84')
})

+ 92
- 0
tests/samples/hitachi-HDS723020BLA642.txt View File

@@ -0,0 +1,92 @@
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-327.36.3.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family: Hitachi Deskstar 7K3000
Device Model: Hitachi HDS723020BLA642
Serial Number: XXXXXXXXXXXXXX
LU WWN Device Id: 5 000cca 369ccd8b5
Firmware Version: MN6OA580
User Capacity: 2,000,398,934,016 bytes [2.00 TB]
Sector Size: 512 bytes logical/physical
Rotation Rate: 7200 rpm
Device is: In smartctl database [for details use: -P show]
ATA Version is: ATA8-ACS T13/1699-D revision 4
SATA Version is: SATA 2.6, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is: Fri Oct 28 12:45:14 2016 UTC
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: (0x80) Offline data collection activity
was never started.
Auto Offline Data Collection: Enabled.
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: (18096) seconds.
Offline data collection
capabilities: (0x5b) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
Offline surface scan supported.
Self-test supported.
No 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: ( 1) minutes.
Extended self-test routine
recommended polling time: ( 302) minutes.
SCT capabilities: (0x003d) 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 0x000b 100 100 016 Pre-fail Always - 0
2 Throughput_Performance 0x0005 136 136 054 Pre-fail Offline - 82
3 Spin_Up_Time 0x0007 164 164 024 Pre-fail Always - 354 (Average 343)
4 Start_Stop_Count 0x0012 100 100 000 Old_age Always - 52
5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always - 84
7 Seek_Error_Rate 0x000b 100 100 067 Pre-fail Always - 0
8 Seek_Time_Performance 0x0005 133 133 020 Pre-fail Offline - 27
9 Power_On_Hours 0x0012 094 094 000 Old_age Always - 44407
10 Spin_Retry_Count 0x0013 100 100 060 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 50
192 Power-Off_Retract_Count 0x0032 099 099 000 Old_age Always - 1207
193 Load_Cycle_Count 0x0012 099 099 000 Old_age Always - 1207
194 Temperature_Celsius 0x0002 166 166 000 Old_age Always - 36 (Min/Max 21/47)
196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always - 98
197 Current_Pending_Sector 0x0022 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0008 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x000a 200 200 000 Old_age Always - 0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged. [To run self-tests, use: smartctl -t]


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.

Loading…
Cancel
Save