mirror of
https://github.com/eLvErDe/hwraid.git
synced 2025-07-25 23:04:44 +02:00
More debugging hooks, fixed improper pattern matching and drive enumeration..
This commit is contained in:
parent
67372fa585
commit
be7e6a0211
@ -29,6 +29,8 @@ printcontroller = True
|
|||||||
debugmode = False
|
debugmode = False
|
||||||
notempmode = False
|
notempmode = False
|
||||||
totaldrivenumber = 0
|
totaldrivenumber = 0
|
||||||
|
totalconfdrivenumber = 0
|
||||||
|
totalunconfdrivenumber = 0
|
||||||
|
|
||||||
# Hardcode a max of 16 HBA and 128 LDs for now. LDTable must be initialized to accept populating list of LD's into each ctlr's list.
|
# Hardcode a max of 16 HBA and 128 LDs for now. LDTable must be initialized to accept populating list of LD's into each ctlr's list.
|
||||||
MaxNumHBA = 16
|
MaxNumHBA = 16
|
||||||
@ -38,6 +40,9 @@ NestedLDTable = [[False for i in range(MaxNumLD)] for j in range(MaxNumHBA)]
|
|||||||
|
|
||||||
# Outputs is a 'dict' of all MegaCLI outputs so we can re-use them during loops..
|
# Outputs is a 'dict' of all MegaCLI outputs so we can re-use them during loops..
|
||||||
Outputs = {}
|
Outputs = {}
|
||||||
|
ConfDisks = {}
|
||||||
|
NagiosBadDisks = {}
|
||||||
|
NagiosGoodDisks = {}
|
||||||
|
|
||||||
# Startup
|
# Startup
|
||||||
def print_usage():
|
def print_usage():
|
||||||
@ -131,7 +136,7 @@ def returnWdthFromArrayCol(glarray,idx):
|
|||||||
maxwdth = len(glrow[idx])
|
maxwdth = len(glrow[idx])
|
||||||
return maxwdth
|
return maxwdth
|
||||||
|
|
||||||
# Get command output
|
# Get and cache command output
|
||||||
def getOutput(cmd):
|
def getOutput(cmd):
|
||||||
lines = []
|
lines = []
|
||||||
if ( Outputs.has_key(cmd) ):
|
if ( Outputs.has_key(cmd) ):
|
||||||
@ -146,6 +151,17 @@ def getOutput(cmd):
|
|||||||
Outputs[cmd] = lines
|
Outputs[cmd] = lines
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
# Get and cache disks, make sure we don't count the same disk twice
|
||||||
|
def AddDisk(mytable,disk):
|
||||||
|
lines = []
|
||||||
|
if ( mytable.has_key(disk) ):
|
||||||
|
dbgprint ("Disk: "+str(disk)+" Already present in Disk Table")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
dbgprint ("Confed "+str(nagiosgooddisk)+'/'+str(nagiosbaddisk)+"Disk: "+str(disk)+" Not already present in Disk Table, adding")
|
||||||
|
mytable[disk] = True
|
||||||
|
return True
|
||||||
|
|
||||||
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()):
|
||||||
@ -165,23 +181,29 @@ def returnRebuildProgress(output):
|
|||||||
percent = int(tmpstr.split('%')[0].strip())
|
percent = int(tmpstr.split('%')[0].strip())
|
||||||
return percent
|
return percent
|
||||||
|
|
||||||
def returnConfDriveNumber(output):
|
def returnConfDriveNumber(controllerid,output):
|
||||||
# Count the configured drives
|
# Count the configured drives
|
||||||
confdrives = 0
|
confdrives = 0 ; enclid = 'N/A' ; slotid = 'N/A'
|
||||||
for line in output:
|
for line in output:
|
||||||
if re.match(r'.*Number of PDs:.*$',line.strip()):
|
|
||||||
confdrives += int(line.split(':')[2].strip())
|
if re.match(r'Enclosure Device ID: .*$',line.strip()):
|
||||||
|
# We match here early in the analysis so reset the vars if this is a new disk we're reading..
|
||||||
|
enclid = line.split(':')[1].strip()
|
||||||
|
elif re.match(r'Slot Number: .*$',line.strip()):
|
||||||
|
slotid = line.split(':')[1].strip()
|
||||||
|
if ( AddDisk(ConfDisks, str(controllerid) + enclid + slotid)):
|
||||||
|
confdrives += 1
|
||||||
return int(confdrives)
|
return int(confdrives)
|
||||||
|
|
||||||
def returnUnConfDriveNumber(output):
|
def returnUnConfDriveNumber(output):
|
||||||
# Count the configured drives
|
# Count the un-configured/Hotspare drives
|
||||||
confdrives = 0
|
unconfdrives = 0
|
||||||
for line in output:
|
for line in output:
|
||||||
if re.match(r'^Firmware state: Unconfigured.*$',line.strip()):
|
if re.match(r'^Firmware state: Unconfigured.*$',line.strip()):
|
||||||
confdrives += 1
|
unconfdrives += 1
|
||||||
if re.match(r'^Firmware state: Hotspare.*$',line.strip()):
|
elif re.match(r'^Firmware state: Hotspare.*$',line.strip()):
|
||||||
confdrives += 1
|
unconfdrives += 1
|
||||||
return int(confdrives)
|
return int(unconfdrives)
|
||||||
|
|
||||||
def returnControllerModel(output):
|
def returnControllerModel(output):
|
||||||
for line in output:
|
for line in output:
|
||||||
@ -435,8 +457,8 @@ def returnDiskInfo(output,controllerid):
|
|||||||
elif re.match(r'^(CacheCade )?Virtual (Disk|Drive): [0-9]+.*$',line.strip()):
|
elif re.match(r'^(CacheCade )?Virtual (Disk|Drive): [0-9]+.*$',line.strip()):
|
||||||
arrayindex += 1
|
arrayindex += 1
|
||||||
arrayid = line.split('(')[0].split(':')[1].strip()
|
arrayid = line.split('(')[0].split(':')[1].strip()
|
||||||
elif re.match(r'^Drive.s pos[a-z]*tion: DiskGroup: [0-9]+,.*$',line.strip()):
|
elif re.match(r'^Drive.s posi*tion: DiskGroup: [0-9]+,.*$',line.strip()):
|
||||||
arrayid = line.split(',')[1].split(':')[1].strip()
|
notarrayid = line.split(',')[1].split(':')[1].strip()
|
||||||
elif re.match(r'PD: [0-9]+ Information.*$',line.strip()):
|
elif re.match(r'PD: [0-9]+ Information.*$',line.strip()):
|
||||||
diskid = line.split()[1].strip()
|
diskid = line.split()[1].strip()
|
||||||
elif re.match(r'^Device Id: .*$',line.strip()):
|
elif re.match(r'^Device Id: .*$',line.strip()):
|
||||||
@ -522,7 +544,7 @@ def returnUnconfDiskInfo(output,controllerid):
|
|||||||
dsize = line.split(':')[1].strip()
|
dsize = line.split(':')[1].strip()
|
||||||
dsize = re.sub(' \[.*\.*$', '', dsize)
|
dsize = re.sub(' \[.*\.*$', '', dsize)
|
||||||
dsize = re.sub('[0-9][0-9] GB', ' Gb', dsize)
|
dsize = re.sub('[0-9][0-9] GB', ' Gb', dsize)
|
||||||
elif re.match(r'^Drive.s pos[a-z]*tion: DiskGroup: [0-9]+,.*$',line.strip()):
|
elif re.match(r'^Drive.s posi*tion: DiskGroup: [0-9]+,.*$',line.strip()):
|
||||||
arrayid = line.split(',')[1].split(':')[1].strip()
|
arrayid = line.split(',')[1].split(':')[1].strip()
|
||||||
elif re.match(r'^Device Id: [0-9]+.*$',line.strip()):
|
elif re.match(r'^Device Id: [0-9]+.*$',line.strip()):
|
||||||
diskid = line.split(':')[1].strip()
|
diskid = line.split(':')[1].strip()
|
||||||
@ -562,9 +584,9 @@ def returnUnconfDiskInfo(output,controllerid):
|
|||||||
if arrayid == False:
|
if arrayid == False:
|
||||||
if subfstate == 'Unconfigured':
|
if subfstate == 'Unconfigured':
|
||||||
dbgprint('Unconfigured Disk: Arrayid: '+str(arrayid)+' DiskId: '+str(diskid)+' '+str(olddiskid)+' '+str(fstate))
|
dbgprint('Unconfigured Disk: Arrayid: '+str(arrayid)+' DiskId: '+str(diskid)+' '+str(olddiskid)+' '+str(fstate))
|
||||||
table.append([ mtype, model, dsize, fstate, speed, temp, enclid, slotid, lsidid])
|
|
||||||
elif subfstate == 'Online, Spun Up':
|
elif subfstate == 'Online, Spun Up':
|
||||||
dbgprint('Online Disk: Arrayid: '+str(arrayid)+' DiskId: '+str(diskid)+' '+str(olddiskid)+' '+str(fstate))
|
dbgprint('Online Disk: Arrayid: '+str(arrayid)+' DiskId: '+str(diskid)+' '+str(olddiskid)+' '+str(fstate))
|
||||||
|
table.append([ mtype, model, dsize, fstate, speed, temp, enclid, slotid, lsidid])
|
||||||
return table
|
return table
|
||||||
|
|
||||||
cmd = '%s -adpCount -NoLog' % (megaclipath)
|
cmd = '%s -adpCount -NoLog' % (megaclipath)
|
||||||
@ -741,18 +763,21 @@ if totaldrivenumber:
|
|||||||
cmd = '%s -LDInfo -lall -a%d -NoLog' % (megaclipath, controllerid)
|
cmd = '%s -LDInfo -lall -a%d -NoLog' % (megaclipath, controllerid)
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arraynumber = returnArrayNumber(output)
|
arraynumber = returnArrayNumber(output)
|
||||||
#### BUG: -LdPdInfo shows all PD on the adapter, not just for said LD..
|
#### BUG: -LdPdInfo shows all PD on the adapter, not just for the LD we wanted..
|
||||||
#### while arrayid <= arraynumber:
|
#### while arrayid <= arraynumber:
|
||||||
cmd = '%s -LdPdInfo -a%d -NoLog' % (megaclipath, controllerid)
|
cmd = '%s -LdPdInfo -a%d -NoLog' % (megaclipath, controllerid)
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arraydisk = returnDiskInfo(output,controllerid)
|
arraydisk = returnDiskInfo(output,controllerid)
|
||||||
for array in arraydisk:
|
for array in arraydisk:
|
||||||
dbgprint('Disk c'+str(controllerid)+'u'+array[0]+'p'+array[1] + ' status : ' + array[5])
|
diskname = str(controllerid) + array[8] + array[9]
|
||||||
if array[5] not in [ 'Online', 'Online, Spun Up' ]:
|
dbgprint('Disk c'+diskname + ' status : ' + array[5])
|
||||||
bad = True
|
if re.match("|".join([ '^Online$', '^Online, Spun Up$', '^Rebuilding \(.*' ]), array[5]):
|
||||||
nagiosbaddisk += 1
|
if ( AddDisk(NagiosGoodDisks, diskname) ):
|
||||||
|
nagiosgooddisk += 1
|
||||||
else:
|
else:
|
||||||
nagiosgooddisk += 1
|
bad = True
|
||||||
|
if ( AddDisk(NagiosBadDisks, diskname) ):
|
||||||
|
nagiosbaddisk += 1
|
||||||
|
|
||||||
if ( returnWdthFromArrayCol(arraydisk,0) > dlen):
|
if ( returnWdthFromArrayCol(arraydisk,0) > dlen):
|
||||||
dlen = returnWdthFromArrayCol(arraydisk,0)
|
dlen = returnWdthFromArrayCol(arraydisk,0)
|
||||||
@ -808,7 +833,7 @@ totaldrivenumber = 0
|
|||||||
while controllerid < controllernumber:
|
while controllerid < controllernumber:
|
||||||
cmd = '%s -LdPdInfo -a%d -NoLog' % (megaclipath, controllerid)
|
cmd = '%s -LdPdInfo -a%d -NoLog' % (megaclipath, controllerid)
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
totalconfdrivenumber += returnConfDriveNumber(output)
|
totalconfdrivenumber += returnConfDriveNumber(controllerid,output)
|
||||||
|
|
||||||
cmd = '%s -PDGetNum -a%d -NoLog' % (megaclipath, controllerid)
|
cmd = '%s -PDGetNum -a%d -NoLog' % (megaclipath, controllerid)
|
||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
@ -842,12 +867,12 @@ if totalunconfdrivenumber:
|
|||||||
output = getOutput(cmd)
|
output = getOutput(cmd)
|
||||||
arraydisk = returnUnconfDiskInfo(output,controllerid)
|
arraydisk = returnUnconfDiskInfo(output,controllerid)
|
||||||
for array in arraydisk:
|
for array in arraydisk:
|
||||||
dbgprint('Disk c'+str(controllerid)+'uXpY status : ' + array[3])
|
dbgprint('Unconfed '+str(nagiosgooddisk)+'/'+str(nagiosbaddisk)+' Disk c'+str(controllerid)+'uXpY status : ' + array[3])
|
||||||
if array[3] not in [ 'Online', 'Unconfigured(good), Spun Up', 'Unconfigured(good), Spun down', 'JBOD','Hotspare, Spun Up','Hotspare, Spun down' ]:
|
if array[3] in [ 'Online', 'Unconfigured(good), Spun Up', 'Unconfigured(good), Spun down', 'JBOD','Hotspare, Spun Up','Hotspare, Spun down' ]:
|
||||||
|
nagiosgooddisk += 1
|
||||||
|
else:
|
||||||
bad = True
|
bad = True
|
||||||
nagiosbaddisk += 1
|
nagiosbaddisk += 1
|
||||||
else:
|
|
||||||
nagiosgooddisk += 1
|
|
||||||
|
|
||||||
mlen = returnWdthFromArrayCol(arraydisk,1)
|
mlen = returnWdthFromArrayCol(arraydisk,1)
|
||||||
flen = returnWdthFromArrayCol(arraydisk,3)
|
flen = returnWdthFromArrayCol(arraydisk,3)
|
||||||
@ -885,7 +910,13 @@ if (debugmode):
|
|||||||
sys.stderr.write("\n".join("".join(map(str,myd)) for myd in Outputs[myl])+'\n')
|
sys.stderr.write("\n".join("".join(map(str,myd)) for myd in Outputs[myl])+'\n')
|
||||||
dbgprint ('Printing arraydisk[]')
|
dbgprint ('Printing arraydisk[]')
|
||||||
sys.stderr.write("\n".join(" | ".join(map(str,myd)) for myd in arraydisk)+'\n')
|
sys.stderr.write("\n".join(" | ".join(map(str,myd)) for myd in arraydisk)+'\n')
|
||||||
|
dbgprint ('Printing ConfDisks[]')
|
||||||
|
sys.stderr.write("\n".join("".join(map(str,myd)) for myd in ConfDisks)+'\n')
|
||||||
|
dbgprint ('Printing NagiosGoodDisks[]')
|
||||||
|
sys.stderr.write("\n".join("".join(map(str,myd)) for myd in NagiosGoodDisks)+'\n')
|
||||||
|
dbgprint ('Printing NagiosBadDisks[]')
|
||||||
|
sys.stderr.write("\n".join("".join(map(str,myd)) for myd in NagiosBadDisks)+'\n')
|
||||||
|
|
||||||
if nagiosmode:
|
if nagiosmode:
|
||||||
if bad:
|
if bad:
|
||||||
print 'RAID ERROR - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
print 'RAID ERROR - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
||||||
@ -894,6 +925,5 @@ if nagiosmode:
|
|||||||
print 'RAID OK - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
print 'RAID OK - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
||||||
else:
|
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 NOT in an OPTIMAL state.: Arrays: OK:'+str(nagiosgoodarray)+', Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+', Bad:'+str(nagiosbaddisk)
|
||||||
print 'RAID ERROR - Arrays: OK:'+str(nagiosgoodarray)+' Bad:'+str(nagiosbadarray)+' - Disks: OK:'+str(nagiosgooddisk)+' Bad:'+str(nagiosbaddisk)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user