aacraid-status: Nagios mode

This commit is contained in:
Adam Cecile 2016-09-19 10:58:22 +02:00
parent aefa54b9cf
commit c19d41d276

View File

@ -194,8 +194,9 @@ controllernumber = returnControllerNumber(output)
# List controllers # List controllers
if printcontroller: if printcontroller:
print '-- Controller informations --' if not config.nagios:
print '-- ID | Model | Status' print '-- Controller informations --'
print '-- ID | Model | Status'
controllerid = 1 controllerid = 1
while controllerid <= controllernumber: while controllerid <= controllernumber:
cmd = '"%s" GETCONFIG %d' % (arcconfpath, controllerid) cmd = '"%s" GETCONFIG %d' % (arcconfpath, controllerid)
@ -204,15 +205,21 @@ if printcontroller:
controllerstatus = returnControllerStatus(output) controllerstatus = returnControllerStatus(output)
if controllerstatus != 'Optimal': if controllerstatus != 'Optimal':
bad = True bad = True
print 'c'+str(controllerid-1)+' | '+controllermodel+' | '+controllerstatus nagiosbadctrl += 1
else:
nagiosgoodctrl += 1
if not config.nagios:
print 'c'+str(controllerid-1)+' | '+controllermodel+' | '+controllerstatus
controllerid += 1 controllerid += 1
print '' if not config.nagios:
print ''
# List arrays # List arrays
if printarray: if printarray:
controllerid = 1 controllerid = 1
print '-- Arrays informations --' if not config.nagios:
print '-- ID | Type | Size | Status | Task | Progress' print '-- Arrays informations --'
print '-- ID | Type | Size | Status | Task | Progress'
while controllerid <= controllernumber: while controllerid <= controllernumber:
arrayid = 0 arrayid = 0
cmd = '"%s" GETCONFIG %s' % (arcconfpath, controllerid) cmd = '"%s" GETCONFIG %s' % (arcconfpath, controllerid)
@ -223,7 +230,10 @@ if printarray:
output = getOutput(cmd) output = getOutput(cmd)
arrayinfo = returnArrayInfo(output) arrayinfo = returnArrayInfo(output)
if arrayinfo[1] != 'Optimal': if arrayinfo[1] != 'Optimal':
nagiosbadarray += 1
bad = True bad = True
else:
nagiosgoodarray += 1
cmd = '"%s" GETSTATUS %s', (arcconfpath, controllerid) cmd = '"%s" GETSTATUS %s', (arcconfpath, controllerid)
output = getOutput(cmd) output = getOutput(cmd)
tasksinfo = returnControllerTasks(output) tasksinfo = returnControllerTasks(output)
@ -237,18 +247,22 @@ if printarray:
raidtype = arrayinfo[0] raidtype = arrayinfo[0]
for tasks in tasksinfo: for tasks in tasksinfo:
if int(tasks[0]) == int(arrayid): if int(tasks[0]) == int(arrayid):
print 'c'+str(controllerid-1)+'u'+str(arrayid)+' | '+raidtype+' | '+arrayinfo[2]+'G | '+arrayinfo[1]+' | '+tasks[1]+' | '+tasks[2]+'%' if not config.nagios:
print 'c'+str(controllerid-1)+'u'+str(arrayid)+' | '+raidtype+' | '+arrayinfo[2]+'G | '+arrayinfo[1]+' | '+tasks[1]+' | '+tasks[2]+'%'
done = True done = True
break break
if done == False: if done == False:
print 'c'+str(controllerid-1)+'u'+str(arrayid)+' | '+raidtype+' | '+arrayinfo[2]+'G | '+arrayinfo[1] if not config.nagios:
print 'c'+str(controllerid-1)+'u'+str(arrayid)+' | '+raidtype+' | '+arrayinfo[2]+'G | '+arrayinfo[1]
controllerid += 1 controllerid += 1
print '' if not config.nagios:
print ''
# List disks # List disks
controllerid = 1 controllerid = 1
print '-- Disks informations' if not config.nagios:
print '-- ID | Model | Status' print '-- Disks informations'
print '-- ID | Model | Status'
while controllerid <= controllernumber: while controllerid <= controllernumber:
arrayid = 0 arrayid = 0
cmd = '"%s" GETCONFIG %s' % (arcconfpath, controllerid) cmd = '"%s" GETCONFIG %s' % (arcconfpath, controllerid)
@ -264,19 +278,31 @@ while controllerid <= controllernumber:
for member in arrayinfo[3]: for member in arrayinfo[3]:
i = 0 i = 0
for disk in diskinfo: for disk in diskinfo:
if disk[1] != 'Online' and disk[1] != 'Hot Spare' and disk[1] != 'Ready':
if disk[1] != 'Online' and disk[1] != 'Hot Spare' and disk[1] != 'Ready' and disk[1] != 'Global Hot-Spare':
bad = True bad = True
nagiosbaddisk += 1
else:
nagiosgooddisk += 1
if disk[0] == member: if disk[0] == member:
print 'c'+str(controllerid-1)+'u'+str(arrayid)+'d'+str(i)+' | '+disk[2]+' '+disk[3]+' | '+disk[1] if not config.nagios:
# Remove from disks list print 'c'+str(controllerid-1)+'u'+str(arrayid)+'d'+str(i)+' | '+disk[2]+' '+disk[3]+' | '+disk[1]
del diskinfo[i] # Some disks may not be attached to an array (ie: global hot spare)
else:
if not config.nagios:
print 'c'+str(controllerid-1)+'uX'+'d'+str(i)+' | '+disk[2]+' '+disk[3]+' | '+disk[1]
i += 1 i += 1
# Some disks may not be attached to an array (ie: global hot spare)
for unattached_disk in diskinfo:
print 'c'+str(controllerid-1)+'uX'+'d'+str(i)+' | '+disk[2]+' '+disk[3]+' | '+disk[1]
controllerid += 1 controllerid += 1
if bad: if config.nagios:
print '\nThere is at least one disk/array in a NOT OPTIMAL state.' if bad:
print '\nUse "arcconf GETCONFIG [1-9]" to get details.' print('RAID ERROR - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d' % (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, nagiosbaddisk))
sys.exit(1) sys.exit(2)
else:
print('RAID OK - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d' % (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, nagiosbaddisk))
else:
if bad:
print '\nThere is at least one disk/array in a NOT OPTIMAL state.'
print '\nUse "arcconf GETCONFIG [1-9]" to get details.'
sys.exit(1)