Skip to content

Commit

Permalink
Fixes #23. Also addresses false USB errors in AHCI mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodysu committed Jan 14, 2019
1 parent e9240c6 commit 8d839b8
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions mini_ipmi_smartctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,20 @@ def getDiskTempA(dA):
except:
pA = ''

tempA = re.search('Temperature_Celsius\s+\w+\s+\d+\s+\d+\s+\d+\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+(\d+)\s', pA, re.I)
tempSAS = re.search('Current\s+Drive\s+Temperature:\s+(\d+)\s+', pA, re.I)

if tempA:
if sys.argv[1] == 'getverb': print('getDiskTempA called:', tempA.group(1)) # DEBUG
resultA = tempA.group(1)
elif tempSAS:
if sys.argv[1] == 'getverb': print('getDiskTempSAS called:', tempSAS.group(1)) # DEBUG
resultA = tempSAS.group(1)
else:
if sys.argv[1] == 'getverb': print('getDiskTempA called: None') # DEBUG
resultA = None
# First match returned right away
patterns = (
'^(?:\s+)?\d+\s+Temperature_Celsius\s+[\w-]+\s+\d{3}\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+(\d+)', \
'^Current\s+Drive\s+Temperature:\s+(\d+)\s+', \
'^Temperature:\s+(\d+)\s+C', \
'^(?:\s+)?\d+\s+Airflow_Temperature_Cel\s+[\w-]+\s+\d{3}\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+[\w-]+\s+(\d+)', \
)

resultA = None
for i in patterns:
temperatureRe = re.search(i, pA, re.I | re.M)
if temperatureRe:
resultA = temperatureRe.group(1)
break

return resultA

Expand Down Expand Up @@ -143,14 +145,20 @@ def getDisksTempSCT():

break # configuration error
except subprocess.CalledProcessError as e: # handle process-specific errors
p = e.output # substitute output even on error, so it can be processed further

m2 = "Unknown USB bridge"
if m2 in p:
sender.append('%s mini.disk.info[%s,DriveStatus] "UNK_USB_BRIDGE"' % (host, dR))
continue

if not e.args: # unnecessary for python3?
sender.append('%s mini.disk.info[%s,DriveStatus] "UNKNOWN_RESPONSE"' % (host, dR))
continue
elif e.args[0] == 1 or e.args[0] == 2: # non-fatal disk error codes are not a concern for temperature monitoring script
sender.append(host + ' mini.disk.info[' + dR + ',DriveStatus] "ERR_CODE_' + str(e.args[0]) + '"')
continue # continue to the next disk on fatal error

p = e.output # substitute output even on error, so it can be processed further
except Exception as e:
localError = 'UNKNOWN_EXC_ERROR'

Expand All @@ -163,7 +171,6 @@ def getDisksTempSCT():
p = ''

temp = re.search(r'Current\s+Temperature:\s+(\d+)\s+Celsius', p, re.I)

if temp:
tempResult = temp.group(1)
else: # if nothing was found - try regular SMART command
Expand Down

0 comments on commit 8d839b8

Please sign in to comment.