mirror of
https://github.com/eLvErDe/hwraid.git
synced 2025-07-29 16:54:00 +02:00
Initial revision (Rev 1.1)
This commit is contained in:
parent
daad522781
commit
482023d8b1
@ -1,41 +1,24 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# $Id: megaclisas-status,v 1.1 2011/01/14 09:10:44 root Exp $
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
binarypath = "/usr/sbin/megacli"
|
|
||||||
|
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
print 'Usage: megaclisas-status [--nagios]'
|
print 'Usage: megaraid-status [-d]'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
nagiosmode=False
|
printarray = True
|
||||||
nagiosoutput=''
|
printcontroller = True
|
||||||
nagiosgoodarray=0
|
|
||||||
nagiosbadarray=0
|
|
||||||
nagiosgooddisk=0
|
|
||||||
nagiosbaddisk=0
|
|
||||||
|
|
||||||
# Check command line arguments to enable nagios or not
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
if sys.argv[1] == '--nagios':
|
if sys.argv[1] == '-d':
|
||||||
nagiosmode=True
|
printarray = False
|
||||||
|
printcontroller = False
|
||||||
else:
|
else:
|
||||||
print 'Usage: megaclisas-status [-nagios]'
|
print 'Usage: megaraid-status [-d]'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check binary exists (and +x), if not print an error message
|
|
||||||
# or return UNKNOWN nagios error code
|
|
||||||
if os.path.exists(binarypath) and os.access(binarypath, os.X_OK):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if nagiosmode:
|
|
||||||
print 'UNKNOWN - Cannot find '+binarypath
|
|
||||||
else:
|
|
||||||
print 'Cannot find '+binarypath+'. Please install it.'
|
|
||||||
sys.exit(3)
|
|
||||||
|
|
||||||
# Get command output
|
# Get command output
|
||||||
def getOutput(cmd):
|
def getOutput(cmd):
|
||||||
output = os.popen(cmd)
|
output = os.popen(cmd)
|
||||||
@ -58,24 +41,18 @@ def returnControllerModel(output):
|
|||||||
def returnArrayNumber(output):
|
def returnArrayNumber(output):
|
||||||
i = 0
|
i = 0
|
||||||
for line in output:
|
for line in output:
|
||||||
if re.match(r'^Number of Virtual (Disk|Drive).*$',line.strip()):
|
if re.match(r'^Virtual Disk.*$',line.strip()):
|
||||||
i = line.strip().split(':')[1].strip()
|
i += 1
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def returnArrayInfo(output,controllerid,arrayid):
|
def returnArrayInfo(output,controllerid,arrayid):
|
||||||
id = 'c'+str(controllerid)+'u'+str(arrayid)
|
id = 'c'+str(controllerid)+'u'+str(arrayid)
|
||||||
operationlinennumber = False
|
operationlinennumber = False
|
||||||
linenumber = 0
|
linenumber = 0
|
||||||
|
|
||||||
for line in output:
|
for line in output:
|
||||||
if re.match(r'Number Of Drives\s*((per span))?:.*[0-9]+$',line.strip()):
|
if re.match(r'^RAID Level:.*$',line.strip()):
|
||||||
ldpdcount = line.split(':')[1].strip()
|
type = 'RAID'+line.strip().split(':')[1].split(',')[0].split('-')[1].strip()
|
||||||
if re.match(r'Span Depth *:.*[0-9]+$',line.strip()):
|
if re.match(r'^Size:.*$',line.strip()):
|
||||||
spandepth = line.split(':')[1].strip()
|
|
||||||
if re.match(r'^RAID Level\s*:.*$',line.strip()):
|
|
||||||
raidlevel = line.strip().split(':')[1].split(',')[0].split('-')[1].strip()
|
|
||||||
type = 'RAID' + raidlevel
|
|
||||||
if re.match(r'^Size\s*:.*$',line.strip()):
|
|
||||||
# Size reported in MB
|
# Size reported in MB
|
||||||
if re.match(r'^.*MB$',line.strip().split(':')[1]):
|
if re.match(r'^.*MB$',line.strip().split(':')[1]):
|
||||||
size = line.strip().split(':')[1].strip('MB').strip()
|
size = line.strip().split(':')[1].strip('MB').strip()
|
||||||
@ -88,31 +65,26 @@ def returnArrayInfo(output,controllerid,arrayid):
|
|||||||
else:
|
else:
|
||||||
size = line.strip().split(':')[1].strip('GB').strip()
|
size = line.strip().split(':')[1].strip('GB').strip()
|
||||||
size = str(int(round((float(size)))))+'G'
|
size = str(int(round((float(size)))))+'G'
|
||||||
if re.match(r'^State\s*:.*$',line.strip()):
|
if re.match(r'^State:.*$',line.strip()):
|
||||||
state = line.strip().split(':')[1].strip()
|
state = line.strip().split(':')[1].strip()
|
||||||
if re.match(r'^Ongoing Progresses\s*:.*$',line.strip()):
|
if re.match(r'^Ongoing Progresses:.*$',line.strip()):
|
||||||
operationlinennumber = linenumber
|
operationlinennumber = linenumber
|
||||||
linenumber += 1
|
linenumber += 1
|
||||||
if operationlinennumber:
|
if operationlinennumber:
|
||||||
inprogress = output[operationlinennumber+1]
|
inprogress = output[operationlinennumber+1]
|
||||||
else:
|
else:
|
||||||
inprogress = 'None'
|
inprogress = 'None'
|
||||||
|
|
||||||
if ldpdcount and (int(spandepth) > 1):
|
|
||||||
ldpdcount = int(ldpdcount) * int(spandepth)
|
|
||||||
if int(raidlevel) < 10:
|
|
||||||
type = type + "0"
|
|
||||||
|
|
||||||
return [id,type,size,state,inprogress]
|
return [id,type,size,state,inprogress]
|
||||||
|
|
||||||
def returnDiskInfo(output,controllerid):
|
def returnDiskInfo(output,controllerid):
|
||||||
arrayid = False
|
arrayid = False
|
||||||
diskid = False
|
diskid = False
|
||||||
|
olddiskid = False
|
||||||
table = []
|
table = []
|
||||||
state = 'undef'
|
state = 'Offline'
|
||||||
model = 'undef'
|
model = 'Unknown'
|
||||||
for line in output:
|
for line in output:
|
||||||
if re.match(r'^Virtual (Disk|Drive): [0-9]+.*$',line.strip()):
|
if re.match(r'^Virtual Disk: [0-9]+.*$',line.strip()):
|
||||||
arrayid = line.split('(')[0].split(':')[1].strip()
|
arrayid = line.split('(')[0].split(':')[1].strip()
|
||||||
if re.match(r'Firmware state: .*$',line.strip()):
|
if re.match(r'Firmware state: .*$',line.strip()):
|
||||||
state = line.split(':')[1].strip()
|
state = line.split(':')[1].strip()
|
||||||
@ -120,89 +92,74 @@ def returnDiskInfo(output,controllerid):
|
|||||||
model = line.split(':')[1].strip()
|
model = line.split(':')[1].strip()
|
||||||
model = re.sub(' +', ' ', model)
|
model = re.sub(' +', ' ', model)
|
||||||
if re.match(r'PD: [0-9]+ Information.*$',line.strip()):
|
if re.match(r'PD: [0-9]+ Information.*$',line.strip()):
|
||||||
|
olddiskid = diskid
|
||||||
diskid = line.split()[1].strip()
|
diskid = line.split()[1].strip()
|
||||||
|
if olddiskid != False:
|
||||||
if arrayid != False and state != 'undef' and model != 'undef' and diskid != False:
|
table.append([str(arrayid), str(olddiskid), state, model])
|
||||||
|
state = 'Offline'
|
||||||
|
model = 'Unknown'
|
||||||
table.append([str(arrayid), str(diskid), state, model])
|
table.append([str(arrayid), str(diskid), state, model])
|
||||||
state = 'undef'
|
|
||||||
model = 'undef'
|
|
||||||
|
|
||||||
return table
|
return table
|
||||||
|
|
||||||
cmd = binarypath+' -adpCount -NoLog'
|
cmd = 'megacli -adpCount -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
controllernumber = returnControllerNumber(output)
|
controllernumber = returnControllerNumber(output)
|
||||||
|
|
||||||
bad = False
|
bad = False
|
||||||
|
|
||||||
# List available controller
|
# List available controller
|
||||||
if not nagiosmode:
|
if printcontroller:
|
||||||
print '-- Controller informations --'
|
print '-- Controller informations --'
|
||||||
print '-- ID | Model'
|
print '-- ID | Model'
|
||||||
controllerid = 0
|
controllerid = 0
|
||||||
while controllerid < controllernumber:
|
while controllerid < controllernumber:
|
||||||
cmd = binarypath+' -AdpAllInfo -a'+str(controllerid)+' -NoLog'
|
cmd = 'megacli -AdpAllInfo -a'+str(controllerid)+' -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
controllermodel = returnControllerModel(output)
|
controllermodel = returnControllerModel(output)
|
||||||
print 'c'+str(controllerid)+' | '+controllermodel
|
print 'c'+str(controllerid)+' | '+controllermodel
|
||||||
controllerid += 1
|
controllerid += 1
|
||||||
print ''
|
print ''
|
||||||
|
|
||||||
|
if printarray:
|
||||||
controllerid = 0
|
controllerid = 0
|
||||||
if not nagiosmode:
|
|
||||||
print '-- Arrays informations --'
|
print '-- Arrays informations --'
|
||||||
print '-- ID | Type | Size | Status | InProgress'
|
print '-- ID | Type | Size | Status | InProgress'
|
||||||
|
|
||||||
while controllerid < controllernumber:
|
while controllerid < controllernumber:
|
||||||
arrayid = 0
|
arrayid = 0
|
||||||
cmd = binarypath+' -LdGetNum -a'+str(controllerid)+' -NoLog'
|
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arraynumber = returnArrayNumber(output)
|
arraynumber = returnArrayNumber(output)
|
||||||
while arrayid < int(arraynumber):
|
while arrayid < arraynumber:
|
||||||
cmd = binarypath+' -LDInfo -l'+str(arrayid)+' -a'+str(controllerid)+' -NoLog'
|
cmd = 'megacli -LDInfo -l'+str(arrayid)+' -a'+str(controllerid)+' -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arrayinfo = returnArrayInfo(output,controllerid,arrayid)
|
arrayinfo = returnArrayInfo(output,controllerid,arrayid)
|
||||||
if not nagiosmode:
|
|
||||||
print arrayinfo[0]+' | '+arrayinfo[1]+' | '+arrayinfo[2]+' | '+arrayinfo[3]+' | '+arrayinfo[4]
|
print arrayinfo[0]+' | '+arrayinfo[1]+' | '+arrayinfo[2]+' | '+arrayinfo[3]+' | '+arrayinfo[4]
|
||||||
if not arrayinfo[3] == 'Optimal':
|
if not arrayinfo[3] == 'Optimal':
|
||||||
bad = True
|
bad = True
|
||||||
nagiosbadarray=nagiosbadarray+1
|
|
||||||
else:
|
|
||||||
nagiosgoodarray=nagiosgoodarray+1
|
|
||||||
arrayid += 1
|
arrayid += 1
|
||||||
controllerid += 1
|
controllerid += 1
|
||||||
if not nagiosmode:
|
|
||||||
print ''
|
print ''
|
||||||
|
|
||||||
if not nagiosmode:
|
|
||||||
print '-- Disks informations'
|
print '-- Disks informations'
|
||||||
print '-- ID | Model | Status'
|
print '-- ID | Model | Status'
|
||||||
|
|
||||||
controllerid = 0
|
controllerid = 0
|
||||||
while controllerid < controllernumber:
|
while controllerid < controllernumber:
|
||||||
arrayid = 0
|
arrayid = 0
|
||||||
cmd = binarypath+' -LDInfo -lall -a'+str(controllerid)+' -NoLog'
|
cmd = 'megacli -LDInfo -lall -a'+str(controllerid)+' -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
cmd = binarypath+' -LdPdInfo -a'+str(controllerid)+' -NoLog'
|
arraynumber = returnArrayNumber(output)
|
||||||
|
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
|
||||||
|
#### while arrayid < arraynumber:
|
||||||
|
while arrayid < 1:
|
||||||
|
cmd = 'megacli -LdPdInfo -a'+str(controllerid)+' -NoLog'
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arraydisk = returnDiskInfo(output,controllerid)
|
arraydisk = returnDiskInfo(output,controllerid)
|
||||||
for array in arraydisk:
|
for array in arraydisk:
|
||||||
if not array[2] == 'Online' and not array[2] == 'Online, Spun Up':
|
|
||||||
bad=True
|
|
||||||
nagiosbaddisk=nagiosbaddisk+1
|
|
||||||
else:
|
|
||||||
nagiosgooddisk=nagiosgooddisk+1
|
|
||||||
if not nagiosmode:
|
|
||||||
print 'c'+str(controllerid)+'u'+array[0]+'p'+array[1]+' | '+array[3]+' | '+array[2]
|
print 'c'+str(controllerid)+'u'+array[0]+'p'+array[1]+' | '+array[3]+' | '+array[2]
|
||||||
|
arrayid += 1
|
||||||
controllerid += 1
|
controllerid += 1
|
||||||
|
|
||||||
if nagiosmode:
|
|
||||||
if bad:
|
|
||||||
print 'RAID ERROR - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
|
||||||
sys.exit(2)
|
|
||||||
else:
|
|
||||||
print 'RAID OK - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
|
||||||
else:
|
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user