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 2 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__":
45 45
     parser.add_argument('-f', '--file', help="Use S.M.A.R.T. report from file instead of calling smartctl (Use - to read from stdin)")
46 46
 
47 47
     parser.add_argument('-x', '--exclude-notices', help='Do not report NOTICE warnings (default: %(default)s)', action='store_true', default=False)
48
+    parser.add_argument('-n', '--notices-are-warnings', help='Exit with status code 1 on NOTICEs too (default: %(default)s)', action='store_true', default=False)
49
+
48 50
     parser.add_argument('--ignore-attributes', help='Ignore this S.M.A.R.T. attributes (id or name)', nargs='*')
49 51
     parser.add_argument('-v', '--verbose', help='Verbose messages', action='store_true', default=False)
50 52
     parser.add_argument('--debug', help="Print debug messages", action="store_true", default=False)
@@ -90,6 +92,11 @@ if __name__ == "__main__":
90 92
             if attribute_errors:
91 93
                 msg = ', '.join([ae.long_message if args.verbose else ae.short_message for ae in attribute_errors.values()])
92 94
 
95
+                # set the exit code of NOTICEs to WARNINGs if (-n / --notices-are-warnings) is set
96
+                if args.notices_are_warnings and \
97
+                        any((ae.level == AttributeWarning.Notice for ae in attribute_errors.values())):
98
+                    exit_code = 1
99
+
93 100
                 if any((ae.level == AttributeWarning.Warning for ae in attribute_errors.values())):
94 101
                     exit_code = 1
95 102
                 if any((ae.level == AttributeWarning.Critical for ae in attribute_errors.values())):
@@ -103,7 +110,7 @@ if __name__ == "__main__":
103 110
                 msg = (msg.strip() + '; %s ATA errors found' % check.ata_error_count).lstrip(';').strip()
104 111
                 exit_code = 2
105 112
 
106
-            if not exit_code:
113
+            if not exit_code and not msg:
107 114
                 msg = "S.M.A.R.T. data OK"
108 115
 
109 116
             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_
167 167
                 assert failed_id == 197
168 168
                 assert failed_name == "Current_Pending_Sector"
169 169
                 assert int(failed_attribute.value) == 24
170
+
171
+    def test_notice_warnings(self):
172
+        with open(os.path.join(samples_path, 'hitachi-HDS723020BLA642.txt')) as f:
173
+            check = SMARTCheck(f)
174
+            
175
+            self.assertFalse(check.check())
176
+            
177
+            failed = check.check_attributes()
178
+            
179
+            self.assertEqual(len(failed), 1)
180
+            self.assertEqual(failed, {
181
+                (5, 'Reallocated_Sector_Ct'): AttributeWarning(AttributeWarning.Notice, 'Reallocated_Sector_Ct', '84')
182
+            })

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

@@ -0,0 +1,92 @@
1
+smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-327.36.3.el7.x86_64] (local build)
2
+Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
3
+
4
+=== START OF INFORMATION SECTION ===
5
+Model Family:     Hitachi Deskstar 7K3000
6
+Device Model:     Hitachi HDS723020BLA642
7
+Serial Number:    XXXXXXXXXXXXXX
8
+LU WWN Device Id: 5 000cca 369ccd8b5
9
+Firmware Version: MN6OA580
10
+User Capacity:    2,000,398,934,016 bytes [2.00 TB]
11
+Sector Size:      512 bytes logical/physical
12
+Rotation Rate:    7200 rpm
13
+Device is:        In smartctl database [for details use: -P show]
14
+ATA Version is:   ATA8-ACS T13/1699-D revision 4
15
+SATA Version is:  SATA 2.6, 6.0 Gb/s (current: 3.0 Gb/s)
16
+Local Time is:    Fri Oct 28 12:45:14 2016 UTC
17
+SMART support is: Available - device has SMART capability.
18
+SMART support is: Enabled
19
+
20
+=== START OF READ SMART DATA SECTION ===
21
+SMART overall-health self-assessment test result: PASSED
22
+
23
+General SMART Values:
24
+Offline data collection status:  (0x80)	Offline data collection activity
25
+					was never started.
26
+					Auto Offline Data Collection: Enabled.
27
+Self-test execution status:      (   0)	The previous self-test routine completed
28
+					without error or no self-test has ever 
29
+					been run.
30
+Total time to complete Offline 
31
+data collection: 		(18096) seconds.
32
+Offline data collection
33
+capabilities: 			 (0x5b) SMART execute Offline immediate.
34
+					Auto Offline data collection on/off support.
35
+					Suspend Offline collection upon new
36
+					command.
37
+					Offline surface scan supported.
38
+					Self-test supported.
39
+					No Conveyance Self-test supported.
40
+					Selective Self-test supported.
41
+SMART capabilities:            (0x0003)	Saves SMART data before entering
42
+					power-saving mode.
43
+					Supports SMART auto save timer.
44
+Error logging capability:        (0x01)	Error logging supported.
45
+					General Purpose Logging supported.
46
+Short self-test routine 
47
+recommended polling time: 	 (   1) minutes.
48
+Extended self-test routine
49
+recommended polling time: 	 ( 302) minutes.
50
+SCT capabilities: 	       (0x003d)	SCT Status supported.
51
+					SCT Error Recovery Control supported.
52
+					SCT Feature Control supported.
53
+					SCT Data Table supported.
54
+
55
+SMART Attributes Data Structure revision number: 16
56
+Vendor Specific SMART Attributes with Thresholds:
57
+ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
58
+  1 Raw_Read_Error_Rate     0x000b   100   100   016    Pre-fail  Always       -       0
59
+  2 Throughput_Performance  0x0005   136   136   054    Pre-fail  Offline      -       82
60
+  3 Spin_Up_Time            0x0007   164   164   024    Pre-fail  Always       -       354 (Average 343)
61
+  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       52
62
+  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       84
63
+  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
64
+  8 Seek_Time_Performance   0x0005   133   133   020    Pre-fail  Offline      -       27
65
+  9 Power_On_Hours          0x0012   094   094   000    Old_age   Always       -       44407
66
+ 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
67
+ 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       50
68
+192 Power-Off_Retract_Count 0x0032   099   099   000    Old_age   Always       -       1207
69
+193 Load_Cycle_Count        0x0012   099   099   000    Old_age   Always       -       1207
70
+194 Temperature_Celsius     0x0002   166   166   000    Old_age   Always       -       36 (Min/Max 21/47)
71
+196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       98
72
+197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
73
+198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
74
+199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       0
75
+
76
+SMART Error Log Version: 1
77
+No Errors Logged
78
+
79
+SMART Self-test log structure revision number 1
80
+No self-tests have been logged.  [To run self-tests, use: smartctl -t]
81
+
82
+
83
+SMART Selective self-test log data structure revision number 1
84
+ SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
85
+    1        0        0  Not_testing
86
+    2        0        0  Not_testing
87
+    3        0        0  Not_testing
88
+    4        0        0  Not_testing
89
+    5        0        0  Not_testing
90
+Selective self-test flags (0x0):
91
+  After scanning selected spans, do NOT read-scan remainder of disk.
92
+If Selective self-test is pending on power-up, resume after 0 minute delay.

Loading…
Cancel
Save