From b25b14099469990969c19b4d61788b9ab9b3cc0b Mon Sep 17 00:00:00 2001 From: "Vincent S. Cojot" Date: Wed, 14 Jan 2015 20:22:48 -0500 Subject: [PATCH] Fixes.. (Rev 1.12) --- wrapper-scripts/megaclisas-status | 134 +++++++++++++++++++----------- 1 file changed, 84 insertions(+), 50 deletions(-) diff --git a/wrapper-scripts/megaclisas-status b/wrapper-scripts/megaclisas-status index 9700879..23a2328 100755 --- a/wrapper-scripts/megaclisas-status +++ b/wrapper-scripts/megaclisas-status @@ -1,37 +1,55 @@ #!/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 re import sys +import pdb if len(sys.argv) > 2: - print 'Usage: megaraid-status [-d]' - sys.exit(1) + print 'Usage: megaraid-status [-d]' + sys.exit(1) printarray = True printcontroller = True +totaldrivenumber = 0 + if len(sys.argv) > 1: - if sys.argv[1] == '-d': - printarray = False - printcontroller = False - else: - print 'Usage: megaraid-status [-d]' - sys.exit(1) + if sys.argv[1] == '-d': + printarray = False + printcontroller = False + else: + print 'Usage: megaraid-status [-d]' + sys.exit(1) # Get command output def getOutput(cmd): - output = os.popen(cmd) - lines = [] - for line in output: - if not re.match(r'^$',line.strip()): - lines.append(line.strip()) - return lines + output = os.popen(cmd) + lines = [] + for line in output: + if not re.match(r'^$',line.strip()): + lines.append(line.strip()) + return lines def returnControllerNumber(output): - for line in output: - if re.match(r'^Controller Count.*$',line.strip()): - return int(line.split(':')[1].strip().strip('.')) + for line in output: + if re.match(r'^Controller Count.*$',line.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): for line in output: @@ -230,45 +248,61 @@ if printarray: controllerid += 1 print '' -print '-- 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 -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 + cmd = 'megacli -PDGetNum -a'+str(controllerid)+' -NoLog' + output = getOutput(cmd) + totaldrivenumber += returnTotalDriveNumber(output) + controllerid += 1 +if totaldrivenumber: + print '-- Disks information --' + print '-- ID\t| Model | Status | Speed | Temperature | Slot ID | LSI Device ID ' -print '' -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 -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 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 + cmd = 'megacli -LdPdInfo -a'+str(controllerid)+' -NoLog' + output = getOutput(cmd) + totalunconfdrivenumber += returnUnconfDriveNumber(output) + 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: - print '\nThere is at least one disk/array in a NOT OPTIMAL state.' - sys.exit(1) + print '\nThere is at least one disk/array in a NOT OPTIMAL state.' + sys.exit(1)