Fixes.. (Rev 1.12)

This commit is contained in:
Vincent S. Cojot 2015-01-14 20:22:48 -05:00
parent 4ec7f462d4
commit b25b140994

View File

@ -1,37 +1,55 @@
#!/usr/bin/python #!/usr/bin/python
# $Id: megaclisas-status,v 1.11 2015/01/14 19:24:10 root Exp $ # $Id: megaclisas-status,v 1.12 2015/01/14 20:22:48 root Exp $
import os import os
import re import re
import sys import sys
import pdb
if len(sys.argv) > 2: if len(sys.argv) > 2:
print 'Usage: megaraid-status [-d]' print 'Usage: megaraid-status [-d]'
sys.exit(1) sys.exit(1)
printarray = True printarray = True
printcontroller = True printcontroller = True
totaldrivenumber = 0
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == '-d': if sys.argv[1] == '-d':
printarray = False printarray = False
printcontroller = False printcontroller = False
else: else:
print 'Usage: megaraid-status [-d]' print 'Usage: megaraid-status [-d]'
sys.exit(1) sys.exit(1)
# Get command output # Get command output
def getOutput(cmd): def getOutput(cmd):
output = os.popen(cmd) output = os.popen(cmd)
lines = [] lines = []
for line in output: for line in output:
if not re.match(r'^$',line.strip()): if not re.match(r'^$',line.strip()):
lines.append(line.strip()) lines.append(line.strip())
return lines return lines
def returnControllerNumber(output): def returnControllerNumber(output):
for line in output: for line in output:
if re.match(r'^Controller Count.*$',line.strip()): if re.match(r'^Controller Count.*$',line.strip()):
return int(line.split(':')[1].strip().strip('.')) return int(line.split(':')[1].strip().strip('.'))
def returnTotalDriveNumber(output):
for line in output:
if re.match(r'Number of Physical Drives on Adapter.*$',line.strip()):
return int(line.split(':')[1].strip())
def returnUnconfDriveNumber(output):
configdrives = 0
unconfdrives = 0
for line in output:
if re.match(r'.*Number of PDs:.*$',line.strip()):
configdrives += int(line.split(':')[2].strip())
#### pdb.set_trace()
unconfdrives = totaldrivenumber - configdrives
return int(unconfdrives)
def returnControllerModel(output): def returnControllerModel(output):
for line in output: for line in output:
@ -230,45 +248,61 @@ if printarray:
controllerid += 1 controllerid += 1
print '' print ''
print '-- Disks information --'
print '-- ID\t| Model | Status | Speed | Temperature | Slot ID | LSI Device ID '
controllerid = 0 controllerid = 0
while controllerid < controllernumber: while controllerid < controllernumber:
arrayid = 0 cmd = 'megacli -PDGetNum -a'+str(controllerid)+' -NoLog'
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog' output = getOutput(cmd)
output = getOutput(cmd) totaldrivenumber += returnTotalDriveNumber(output)
arraynumber = returnArrayNumber(output) controllerid += 1
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
#### while arrayid <= arraynumber:
cmd = 'megacli -LdPdInfo -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraydisk = returnDiskInfo(output,controllerid)
for array in arraydisk:
print 'c'+str(controllerid)+'u'+array[0]+'p'+array[1]+'\t| '+array[3]+' | '+array[2]+' | '+array[4]+' | '+array[5]+' | ID: \'['+array[6]+':'+array[7]+']\' | '+array[8]
controllerid += 1
if totaldrivenumber:
print '-- Disks information --'
print '-- ID\t| Model | Status | Speed | Temperature | Slot ID | LSI Device ID '
print '' controllerid = 0
print '-- Unconfigured Disks information --' while controllerid < controllernumber:
print '-- ID\t| Model | Status | Speed | Temperature | Slot ID | LSI Device ID ' arrayid = 0
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraynumber = returnArrayNumber(output)
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
#### while arrayid <= arraynumber:
cmd = 'megacli -LdPdInfo -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraydisk = returnDiskInfo(output,controllerid)
for array in arraydisk:
print 'c'+str(controllerid)+'u'+array[0]+'p'+array[1]+'\t| '+array[3]+' | '+array[2]+' | '+array[4]+' | '+array[5]+' | ID: \'['+array[6]+':'+array[7]+']\' | '+array[8]
controllerid += 1
print ''
totalunconfdrivenumber = 0
controllerid = 0 controllerid = 0
while controllerid < controllernumber: while controllerid < controllernumber:
arrayid = 0 cmd = 'megacli -LdPdInfo -a'+str(controllerid)+' -NoLog'
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog' output = getOutput(cmd)
output = getOutput(cmd) totalunconfdrivenumber += returnUnconfDriveNumber(output)
arraynumber = returnArrayNumber(output) controllerid += 1
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
#### while arrayid <= arraynumber:
cmd = 'megacli -PDList -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraydisk = returnUnconfDiskInfo(output,controllerid)
for array in arraydisk:
print 'c'+str(controllerid)+'\t| '+array[1]+' | '+array[0]+' | '+array[2]+' | '+array[3]+' | ID: \'['+array[4]+':'+array[5]+']\' | '+array[6]
controllerid += 1
if ( totalunconfdrivenumber > 0):
print '-- Unconfigured Disks information --'
print '-- ID\t| Model | Status | Speed | Temperature | Slot ID | LSI Device ID '
controllerid = 0
while controllerid < controllernumber:
arrayid = 0
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraynumber = returnArrayNumber(output)
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
#### while arrayid <= arraynumber:
cmd = 'megacli -PDList -a'+str(controllerid)+' -NoLog'
output = getOutput(cmd)
arraydisk = returnUnconfDiskInfo(output,controllerid)
for array in arraydisk:
print 'c'+str(controllerid)+'\t| '+array[1]+' | '+array[0]+' | '+array[2]+' | '+array[3]+' | ID: \'['+array[4]+':'+array[5]+']\' | '+array[6]
controllerid += 1
print ''
if bad: if bad:
print '\nThere is at least one disk/array in a NOT OPTIMAL state.' print '\nThere is at least one disk/array in a NOT OPTIMAL state.'
sys.exit(1) sys.exit(1)