From fa45565eb08219703f36982cc8bedf4758d61e89 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 13 Aug 2021 10:43:13 +0200 Subject: [PATCH] Update megacli-status to python3 --- megaclisas-status | 78 +++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/megaclisas-status b/megaclisas-status index 3495502..1518baf 100755 --- a/megaclisas-status +++ b/megaclisas-status @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # $Id: megaclisas-status,v 1.68 2016/10/21 14:38:56 root Exp root $ # # Written by Adam Cecile @@ -40,7 +40,7 @@ Outputs = {} # Startup def print_usage(): - print 'Usage: megaraid-status [--nagios|--debug|--notemp]' + print('Usage: megaraid-status [--nagios|--debug|--notemp]') # We need root access to query if __name__ == '__main__': @@ -49,7 +49,7 @@ if __name__ == '__main__': except AttributeError: root_or_admin = ctypes.windll.shell32.IsUserAnAdmin() !=0 if not root_or_admin: - print '# This script requires Administrator privileges' + print('# This script requires Administrator privileges') sys.exit(5) # Check command line arguments to enable nagios or not @@ -102,19 +102,19 @@ for megabin in "MegaCli64","MegaCli","megacli", "MegaCli.exe": if (megaclipath != None): dbgprint ('Will use MegaCLI from here: '+str(megaclipath)) break - + # Check binary exists (and +x), if not print an error message if (megaclipath != None): if os.path.exists(megaclipath) and os.access(megaclipath, os.X_OK): pass else: if nagiosmode: - print 'UNKNOWN - Cannot find '+megaclipath + print('UNKNOWN - Cannot find '+megaclipath) else: - print 'Cannot find ' + megaclipath + 'in your PATH. Please install it.' + print('Cannot find ' + megaclipath + 'in your PATH. Please install it.') sys.exit(3) else: - print 'Cannot find "MegaCli64","MegaCli" or "megacli" or "MegaCli.exe" in your PATH. Please install it.' + print('Cannot find "MegaCli64","MegaCli" or "megacli" or "MegaCli.exe" in your PATH. Please install it.') sys.exit(3) @@ -130,7 +130,7 @@ def returnWdthFromArrayCol(glarray,idx): # Get command output def getOutput(cmd): lines = [] - if ( Outputs.has_key(cmd) ): + if cmd in Outputs: dbgprint ("Got Cached value: "+str(cmd)) lines = Outputs[cmd] else: @@ -141,7 +141,7 @@ def getOutput(cmd): lines.append(line.strip()) Outputs[cmd] = lines return lines - + def returnControllerNumber(output): for line in output: if re.match(r'^Controller Count.*$',line.strip()): @@ -274,7 +274,7 @@ def returnHBAInfo(table,output,controllerid): cmd = '%s -AdpBbuCmd -GetBbuStatus -a%d -NoLog' % (megaclipath, controllerid) output = getOutput(cmd) controllerbbu = returnBBUStatus(output) - + if controllermodel != 'Unknown': table.append([ 'c'+str(controllerid), controllermodel, controllerram, str(controllertemp), str(controllerbbu), str('FW: '+controllerrev) ]) @@ -469,9 +469,9 @@ def returnDiskInfo(output,controllerid): dbgprint('Disk Info: '+str(arrayid)+' '+str(diskid)+' '+str(oldenclid)) if subfstate == 'Rebuild': cmd = '%s pdrbld -showprog -physdrv\[%s:%s\] -a%d -NoLog' % (megaclipath, enclid, slotid, controllerid) - output = getOutput(cmd) - percent = returnRebuildProgress(output) - fstate = str('Rebuilding (%d%%)' % (percent)) + output = getOutput(cmd) + percent = returnRebuildProgress(output) + fstate = str('Rebuilding (%d%%)' % (percent)) if (( NestedLDTable[controllerid][int(arrayindex)] == True) and (spanid != False)): sarrayid = str(arrayid)+"s"+spanid @@ -566,7 +566,7 @@ bad = False if printcontroller: if controllernumber: if not nagiosmode: - print '-- Controller information --' + print('-- Controller information --') i = 0 controllerid = 0 @@ -585,25 +585,25 @@ if printcontroller: # Header if ( i == 0 ): if not nagiosmode: - print hbafmt % ("-- ID","H/W Model","RAM","Temp","BBU", "Firmware") + print(hbafmt % ("-- ID","H/W Model","RAM","Temp","BBU", "Firmware")) if not nagiosmode: - print hbafmt % ( + print(hbafmt % ( hba[0], hba[1], hba[2], hba[3], hba[4], - hba[5]) + hba[5])) i += 1 if not nagiosmode: - print '' + print('') else: - print "No MegaRAID or PERC adapter detected on your system!" + print("No MegaRAID or PERC adapter detected on your system!") exit(1) if printarray: if not nagiosmode: - print '-- Array information --' + print('-- Array information --') controllerid = 0 pcipath = '' @@ -682,9 +682,9 @@ if printarray: # Header if ( i == 0 ): if not nagiosmode: - print ldfmt % ("-- ID", "Type", "Size", "Strpsz", "Flags", "DskCache", "Status", "OS Path", "CacheCade", "InProgress" ) + print(ldfmt % ("-- ID", "Type", "Size", "Strpsz", "Flags", "DskCache", "Status", "OS Path", "CacheCade", "InProgress" )) if not nagiosmode: - print ldfmt % ( + print(ldfmt % ( arrayinfo[0], arrayinfo[1], arrayinfo[2], @@ -694,7 +694,7 @@ if printarray: arrayinfo[6], arrayinfo[7], arrayinfo[8], - arrayinfo[9]) + arrayinfo[9])) dbgprint("Array state : "+arrayinfo[6]) if arrayinfo[6] not in [ 'Optimal', 'N/A' ]: bad = True @@ -705,7 +705,7 @@ if printarray: i += 1 controllerid += 1 if not nagiosmode: - print '' + print('') controllerid = 0 while controllerid < controllernumber: @@ -716,7 +716,7 @@ while controllerid < controllernumber: if totaldrivenumber: if not nagiosmode: - print '-- Disk information --' + print('-- Disk information --') i = 0 dlen = 0 ; mlen = 0 ; flen = 0 @@ -767,11 +767,11 @@ if totaldrivenumber: # Header if ( i == 0 ): if not nagiosmode: - print drvfmt % ( - "-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI Device ID") + print(drvfmt % ( + "-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI Device ID")) # Drive information if not nagiosmode: - print drvfmt % ( + print(drvfmt % ( str('c'+str(controllerid)+'u'+array[0]+'p'+array[1]), # c0p0 array[2], # HDD/SDD array[3], # Model Information (Variable len) @@ -780,11 +780,11 @@ if totaldrivenumber: array[6], # Speed array[7], # Temp str('['+array[8]+':'+array[9]+']'), # Slot ID - array[10]) # LSI ID + array[10])) # LSI ID i = i + 1 controllerid += 1 if not nagiosmode: - print '' + print('') controllerid = 0 totalconfdrivenumber = 0 @@ -811,7 +811,7 @@ dbgprint('Total Unconfigured Drives : ' + str(totalunconfdrivenumber)) if totalunconfdrivenumber: if not nagiosmode: - print '-- Unconfigured Disk information --' + print('-- Unconfigured Disk information --') controllerid = 0 while controllerid < controllernumber: @@ -844,11 +844,11 @@ if totalunconfdrivenumber: # Header if ( i == 0 ): if not nagiosmode: - print drvfmt % ( - "-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI Device ID") + print(drvfmt % ( + "-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI Device ID")) # Drive information if not nagiosmode: - print drvfmt % ( + print(drvfmt % ( str('c'+str(controllerid)+'uXpY'), # cXpY array[0], # HDD/SDD array[1], # Model Information (Variable len) @@ -857,19 +857,19 @@ if totalunconfdrivenumber: array[4], # Speed array[5], # Temp str('['+array[6]+':'+array[7]+']'), # Slot ID - array[8]) # LSI ID + array[8])) # LSI ID i = i + 1 controllerid += 1 if not nagiosmode: - print '' + print('') if nagiosmode: 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)) sys.exit(2) else: - 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: 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)