Lines 1-21
Link Here
|
1 |
--- check_smartmon.orig 2019-03-04 20:08:28 UTC |
1 |
--- check_smartmon.orig 2019-04-16 21:26:22 UTC |
2 |
+++ check_smartmon |
2 |
+++ check_smartmon |
3 |
@@ -161,9 +161,12 @@ def parseOutput(healthMessage, temperatureMessage, dev |
3 |
@@ -52,8 +52,8 @@ def parseCmdLine(args): |
4 |
lines = healthMessage.split("\n") |
4 |
version = "%%prog %s" % (__version__) |
|
|
5 |
|
6 |
parser = OptionParser(usage=usage, version=version) |
7 |
- parser.add_option("-d", "--device", action="store", dest="device", default="", metavar="DEVICE", |
8 |
- help="device to check") |
9 |
+ parser.add_option("-d", "--device", action="store", dest="device", default="", metavar="DEVICE", |
10 |
+ help="device to check") |
11 |
parser.add_option("-v", "--verbosity", action="store", |
12 |
dest="verbosity", type="int", default=0, |
13 |
metavar="LEVEL", help="set verbosity level to LEVEL; defaults to 0 (quiet), \ |
14 |
@@ -123,7 +123,7 @@ def callSmartMonTools(path, device): |
15 |
"") |
16 |
healthStatusOutput = "" |
17 |
for line in child_stdout: |
18 |
- healthStatusOutput = healthStatusOutput + line |
19 |
+ healthStatusOutput = healthStatusOutput + line.decode('utf-8') |
20 |
# done |
21 |
|
22 |
# get temperature |
23 |
@@ -138,7 +138,7 @@ def callSmartMonTools(path, device): |
24 |
|
25 |
temperatureOutput = "" |
26 |
for line in child_stdout: |
27 |
- temperatureOutput = temperatureOutput + line |
28 |
+ temperatureOutput = temperatureOutput + line.decode('utf-8') |
29 |
# done |
30 |
|
31 |
return (0 ,"", healthStatusOutput, temperatureOutput) |
32 |
@@ -153,6 +153,7 @@ def parseOutput(healthMessage, temperatu |
33 |
|
34 |
vprint(3, "parseOutput: Device type is %s" % devType) |
35 |
|
36 |
+ healthStatus = "" |
37 |
if devType == "ata": |
38 |
# parse health status |
39 |
# |
40 |
@@ -162,13 +163,16 @@ def parseOutput(healthMessage, temperatu |
5 |
getNext = 0 |
41 |
getNext = 0 |
6 |
for line in lines: |
42 |
for line in lines: |
7 |
+ vprint(3, "parseOutput: line is: '%s'" % line) |
|
|
8 |
if getNext: |
43 |
if getNext: |
9 |
- statusLine = line |
44 |
- statusLine = line |
10 |
- break |
45 |
- break |
11 |
+ if line <> "SMART STATUS RETURN: incomplete response, ATA output registers missing" and \ |
46 |
+ if line != "SMART STATUS RETURN: incomplete response, ATA output registers missing" and \ |
12 |
+ line <> "SMART Status not supported: Incomplete response, ATA output registers missing" : |
47 |
+ line != "SMART Status not supported: Incomplete response, ATA output registers missing" : |
13 |
+ statusLine = line |
48 |
+ statusLine = line |
14 |
+ break |
49 |
+ break |
15 |
elif line == "=== START OF READ SMART DATA SECTION ===": |
50 |
elif line == "=== START OF READ SMART DATA SECTION ===": |
16 |
getNext = 1 |
51 |
getNext = 1 |
17 |
# fi |
52 |
# fi |
18 |
@@ -181,7 +184,7 @@ def parseOutput(healthMessage, temperatureMessage, dev |
53 |
# done |
|
|
54 |
|
55 |
+ vprint(3, "parseOutput: statusLine is: '%s'" % statusLine ) |
56 |
if getNext: |
57 |
parts = statusLine.split() |
58 |
healthStatus = parts[-1] |
59 |
@@ -181,7 +185,7 @@ def parseOutput(healthMessage, temperatu |
19 |
parts = line.split() |
60 |
parts = line.split() |
20 |
if len(parts): |
61 |
if len(parts): |
21 |
# 194 is the temperature value id |
62 |
# 194 is the temperature value id |
Lines 24-30
Link Here
|
24 |
temperature = int(parts[9]) |
65 |
temperature = int(parts[9]) |
25 |
break |
66 |
break |
26 |
# fi |
67 |
# fi |
27 |
@@ -190,9 +193,11 @@ def parseOutput(healthMessage, temperatureMessage, dev |
68 |
@@ -190,9 +194,11 @@ def parseOutput(healthMessage, temperatu |
28 |
# if devType == ata |
69 |
# if devType == ata |
29 |
|
70 |
|
30 |
if devType == "scsi": |
71 |
if devType == "scsi": |
Lines 37-43
Link Here
|
37 |
if stat_re.search( line ): |
78 |
if stat_re.search( line ): |
38 |
parts = line.split() |
79 |
parts = line.split() |
39 |
healthStatus = parts[-1] |
80 |
healthStatus = parts[-1] |
40 |
@@ -201,14 +206,20 @@ def parseOutput(healthMessage, temperatureMessage, dev |
81 |
@@ -201,19 +207,25 @@ def parseOutput(healthMessage, temperatu |
41 |
# done |
82 |
# done |
42 |
|
83 |
|
43 |
# get temperature from temperatureMessage |
84 |
# get temperature from temperatureMessage |
Lines 60-66
Link Here
|
60 |
# done |
101 |
# done |
61 |
|
102 |
|
62 |
# if devType == scsi |
103 |
# if devType == scsi |
63 |
@@ -225,6 +236,7 @@ def createReturnInfo(healthStatus, temperature, warnin |
104 |
|
|
|
105 |
- vprint(3, "Health status: %s" % healthStatus) |
106 |
+ vprint(3, "Health status: %s" % healthStatus) |
107 |
vprint(3, "Temperature: %d" %temperature) |
108 |
|
109 |
return (healthStatus, temperature) |
110 |
@@ -225,6 +237,7 @@ def createReturnInfo(healthStatus, tempe |
64 |
|
111 |
|
65 |
# this is absolutely critical! |
112 |
# this is absolutely critical! |
66 |
if healthStatus not in [ "PASSED", "OK" ]: |
113 |
if healthStatus not in [ "PASSED", "OK" ]: |
Lines 68-74
Link Here
|
68 |
return (2, "CRITICAL: device does not pass health status") |
115 |
return (2, "CRITICAL: device does not pass health status") |
69 |
# fi |
116 |
# fi |
70 |
|
117 |
|
71 |
@@ -287,6 +299,7 @@ if __name__ == "__main__": |
118 |
@@ -241,7 +254,7 @@ def createReturnInfo(healthStatus, tempe |
|
|
119 |
def exitWithMessage(value, message): |
120 |
"""Exit with given value and status message.""" |
121 |
|
122 |
- print message |
123 |
+ print( message ) |
124 |
sys.exit(value) |
125 |
# end |
126 |
|
127 |
@@ -254,7 +267,7 @@ def vprint(level, message): |
128 |
""" |
129 |
|
130 |
if level <= verbosity: |
131 |
- print message |
132 |
+ print( message ) |
133 |
# fi |
134 |
# end |
135 |
|
136 |
@@ -287,6 +300,7 @@ if __name__ == "__main__": |
72 |
# check device type, ATA is default |
137 |
# check device type, ATA is default |
73 |
vprint(2, "Get device type") |
138 |
vprint(2, "Get device type") |
74 |
devtype = options.devtype |
139 |
devtype = options.devtype |