mirror of https://github.com/eLvErDe/hwraid.git
194 lines
6.6 KiB
Python
Executable File
194 lines
6.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
# $Id: megaclisas-status,v 1.8 2014/01/16 17:59:00 root Exp $
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
if len(sys.argv) > 2:
|
|
print 'Usage: megaraid-status [-d]'
|
|
sys.exit(1)
|
|
|
|
printarray = True
|
|
printcontroller = True
|
|
if len(sys.argv) > 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
|
|
|
|
def returnControllerNumber(output):
|
|
for line in output:
|
|
if re.match(r'^Controller Count.*$',line.strip()):
|
|
return int(line.split(':')[1].strip().strip('.'))
|
|
|
|
def returnControllerModel(output):
|
|
for line in output:
|
|
if re.match(r'^Product Name.*$',line.strip()):
|
|
return line.split(':')[1].strip()
|
|
|
|
def returnMemorySize(output):
|
|
for line in output:
|
|
if re.match(r'^Memory Size.*$',line.strip()):
|
|
return line.split(':')[1].strip()
|
|
|
|
def returnFirmwareVersion(output):
|
|
for line in output:
|
|
if re.match(r'^FW Package Build.*$',line.strip()):
|
|
return line.split(':')[1].strip()
|
|
|
|
def returnArrayNumber(output):
|
|
i = 0
|
|
for line in output:
|
|
if re.match(r'^Virtual Drive:.*$',line.strip()):
|
|
i += 1
|
|
return i
|
|
|
|
def returnArrayInfo(output,controllerid,arrayid):
|
|
id = 'c'+str(controllerid)+'u'+str(arrayid)
|
|
operationlinennumber = False
|
|
linenumber = 0
|
|
type = ''
|
|
size = ''
|
|
state = ''
|
|
for line in output:
|
|
if re.match(r'^RAID Level.*?:.*$',line.strip()):
|
|
type = 'RAID-'+line.strip().split(':')[1].split(',')[0].split('-')[1].strip()
|
|
# type = 'RAID'+line.strip().split(':')[1]
|
|
if re.match(r'^Size.*?:.*$',line.strip()):
|
|
# Size reported in MB
|
|
if re.match(r'^.*MB$',line.strip().split(':')[1]):
|
|
size = line.strip().split(':')[1].strip('MB').strip()
|
|
size = str(int(round((float(size) / 1000))))+'G'
|
|
# Size reported in TB
|
|
elif re.match(r'^.*TB$',line.strip().split(':')[1]):
|
|
size = line.strip().split(':')[1].strip('TB').strip()
|
|
size = str(int(round((float(size) * 1000))))+'G'
|
|
# Size reported in GB (default)
|
|
else:
|
|
size = line.strip().split(':')[1].strip('GB').strip()
|
|
size = str(int(round((float(size)))))+'G'
|
|
if re.match(r'^State.*?:.*$',line.strip()):
|
|
state = line.strip().split(':')[1].strip()
|
|
if re.match(r'^Ongoing Progresses.*?:.*$',line.strip()):
|
|
operationlinennumber = linenumber
|
|
linenumber += 1
|
|
if operationlinennumber:
|
|
inprogress = output[operationlinennumber+1]
|
|
else:
|
|
inprogress = 'None'
|
|
return [id,type,size,state,inprogress]
|
|
|
|
def returnDiskInfo(output,controllerid):
|
|
arrayid = False
|
|
diskid = False
|
|
olddiskid = False
|
|
enclid = False
|
|
slotid = False
|
|
table = []
|
|
state = 'Offline'
|
|
model = 'Unknown'
|
|
speed = 'Unknown'
|
|
temp = 'Unk0C'
|
|
for line in output:
|
|
if re.match(r'^Virtual Drive: [0-9]+.*$',line.strip()):
|
|
arrayid = line.split('(')[0].split(':')[1].strip()
|
|
if re.match(r'PD: [0-9]+ Information.*$',line.strip()):
|
|
olddiskid = diskid
|
|
diskid = line.split()[1].strip()
|
|
if olddiskid != False:
|
|
state = 'Offline'
|
|
model = 'Unknown'
|
|
if re.match(r'Enclosure Device ID: .*$',line.strip()):
|
|
enclid = line.split(':')[1].strip()
|
|
if re.match(r'Slot Number: .*$',line.strip()):
|
|
slotid = line.split(':')[1].strip()
|
|
if re.match(r'Firmware state: .*$',line.strip()):
|
|
state = line.split(':')[1].strip()
|
|
if re.match(r'Inquiry Data: .*$',line.strip()):
|
|
model = line.split(':')[1].strip()
|
|
model = re.sub(' +', ' ', model)
|
|
if re.match(r'Device Speed: .*$',line.strip()):
|
|
speed = line.split(':')[1].strip()
|
|
if re.match(r'Drive Temperature :.*$',line.strip()):
|
|
temp = line.split(':')[1].strip()
|
|
temp = re.sub('\(.*\)', '', temp)
|
|
if model != 'Unknown':
|
|
#### print str(arrayid)+' '+str(diskid)+' '+str(olddiskid)
|
|
table.append([str(arrayid), str(diskid), state, model, speed, temp, enclid, slotid])
|
|
return table
|
|
|
|
cmd = 'megacli -adpCount -NoLog'
|
|
output = getOutput(cmd)
|
|
controllernumber = returnControllerNumber(output)
|
|
|
|
bad = False
|
|
|
|
# List available controller
|
|
if printcontroller:
|
|
print '-- Controller information --'
|
|
print '-- ID | Model'
|
|
controllerid = 0
|
|
while controllerid < controllernumber:
|
|
cmd = 'megacli -AdpAllInfo -a'+str(controllerid)+' -NoLog'
|
|
output = getOutput(cmd)
|
|
controllermodel = returnControllerModel(output)
|
|
controllerram = returnMemorySize(output)
|
|
controllerrev = returnFirmwareVersion(output)
|
|
print 'c'+str(controllerid)+' | '+controllermodel+' ('+controllerram+') FW: '+controllerrev
|
|
controllerid += 1
|
|
print ''
|
|
|
|
if printarray:
|
|
controllerid = 0
|
|
print '-- Arrays informations --'
|
|
print '-- ID | Type | Size | Status | InProgress'
|
|
while controllerid < controllernumber:
|
|
arrayid = 0
|
|
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog'
|
|
output = getOutput(cmd)
|
|
arraynumber = returnArrayNumber(output)
|
|
while arrayid < arraynumber:
|
|
cmd = 'megacli -LDInfo -l'+str(arrayid)+' -a'+str(controllerid)+' -NoLog'
|
|
output = getOutput(cmd)
|
|
arrayinfo = returnArrayInfo(output,controllerid,arrayid)
|
|
print arrayinfo[0]+' | '+arrayinfo[1]+' | '+arrayinfo[2]+' | '+arrayinfo[3]+' | '+arrayinfo[4]
|
|
if not arrayinfo[3] == 'Optimal':
|
|
bad = True
|
|
arrayid += 1
|
|
controllerid += 1
|
|
print ''
|
|
|
|
print '-- Disks informations'
|
|
print '-- ID | Model | Status | Speed | Temperature'
|
|
|
|
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]+' | '+array[3]+' | '+array[2]+' | '+array[4]+' | '+array[5]+'| ID: \'['+array[6]+':'+array[7]+']\''
|
|
controllerid += 1
|
|
|
|
if bad:
|
|
print '\nThere is at least one disk/array in a NOT OPTIMAL state.'
|
|
sys.exit(1)
|