Run 2to3 on all Python wrappers

This commit is contained in:
Adam Cecile 2021-08-17 09:42:37 +02:00
parent e0d3be643a
commit 8e78deda38
7 changed files with 129 additions and 129 deletions

View File

@ -7,7 +7,7 @@ import sys
binarypath = "/usr/sbin/tw-cli" binarypath = "/usr/sbin/tw-cli"
if len(sys.argv) > 2: if len(sys.argv) > 2:
print "Usage: 3ware-status [--nagios]" print("Usage: 3ware-status [--nagios]")
sys.exit(1) sys.exit(1)
nagiosmode = False nagiosmode = False
@ -21,7 +21,7 @@ if len(sys.argv) > 1:
if sys.argv[1] == "--nagios": if sys.argv[1] == "--nagios":
nagiosmode = True nagiosmode = True
else: else:
print "Usage: 3ware-status [--nagios]" print("Usage: 3ware-status [--nagios]")
sys.exit(1) sys.exit(1)
# Check binary exists (and +x), if not print an error message # Check binary exists (and +x), if not print an error message
@ -30,9 +30,9 @@ if os.path.exists(binarypath) and os.access(binarypath, os.X_OK):
pass pass
else: else:
if nagiosmode: if nagiosmode:
print "UNKNOWN - Cannot find " + binarypath print("UNKNOWN - Cannot find " + binarypath)
else: else:
print "Cannot find " + binarypath + ". Please install it." print("Cannot find " + binarypath + ". Please install it.")
sys.exit(3) sys.exit(3)
@ -92,8 +92,8 @@ bad = False
# List available controller # List available controller
if not nagiosmode: if not nagiosmode:
print "-- Controller informations --" print("-- Controller informations --")
print "-- ID | Model" print("-- ID | Model")
for controller in controllerlist: for controller in controllerlist:
cmd = binarypath + " info " + controller + " model" cmd = binarypath + " info " + controller + " model"
# https://github.com/eLvErDe/hwraid/issues/69 # https://github.com/eLvErDe/hwraid/issues/69
@ -101,13 +101,13 @@ if not nagiosmode:
model = getOutput(cmd)[0].split(" = ")[1].strip() model = getOutput(cmd)[0].split(" = ")[1].strip()
except IndexError: except IndexError:
model = "N/A" model = "N/A"
print controller + " | " + model print(controller + " | " + model)
print "" print("")
# List arrays # List arrays
if not nagiosmode: if not nagiosmode:
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID\tType\tSize\tStatus" print("-- ID\tType\tSize\tStatus")
for controller in controllerlist: for controller in controllerlist:
cmd = binarypath + " info " + controller cmd = binarypath + " info " + controller
output = getOutput(cmd) output = getOutput(cmd)
@ -123,14 +123,14 @@ for controller in controllerlist:
else: else:
nagiosgoodarray = nagiosgoodarray + 1 nagiosgoodarray = nagiosgoodarray + 1
if not nagiosmode: if not nagiosmode:
print id + "\t" + type + "\t" + size + "\t" + status print(id + "\t" + type + "\t" + size + "\t" + status)
if not nagiosmode: if not nagiosmode:
print "" print("")
# List disks # List disks
if not nagiosmode: if not nagiosmode:
print "-- Disks informations" print("-- Disks informations")
print "-- ID\tModel\t\t\tStatus" print("-- ID\tModel\t\t\tStatus")
for controller in controllerlist: for controller in controllerlist:
cmd = binarypath + " info " + controller cmd = binarypath + " info " + controller
output = getOutput(cmd) output = getOutput(cmd)
@ -147,19 +147,19 @@ for controller in controllerlist:
else: else:
nagiosgooddisk = nagiosgooddisk + 1 nagiosgooddisk = nagiosgooddisk + 1
if not nagiosmode: if not nagiosmode:
print id + "\t" + model + "\t" + status print(id + "\t" + model + "\t" + status)
if nagiosmode: if nagiosmode:
if bad: if bad:
print "RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk nagiosbaddisk
) ))
sys.exit(2) sys.exit(2)
else: else:
print "RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk 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 in a NOT OPTIMAL state.")
sys.exit(1) sys.exit(1)

View File

@ -225,12 +225,12 @@ if arcconfpath != None:
pass pass
else: else:
if config.nagios: if config.nagios:
print "UNKNOWN - Cannot find " + arcconfpath print("UNKNOWN - Cannot find " + arcconfpath)
else: else:
print "Cannot find " + arcconfpath + "in your PATH. Please install it." print("Cannot find " + arcconfpath + "in your PATH. Please install it.")
sys.exit(3) sys.exit(3)
else: else:
print 'Cannot find "arcconf, "arcconf.exe" in your PATH. Please install it.' print('Cannot find "arcconf, "arcconf.exe" in your PATH. Please install it.')
sys.exit(3) sys.exit(3)
@ -238,14 +238,14 @@ cmd = '"%s" GETVERSION' % arcconfpath
output = getOutput(cmd) output = getOutput(cmd)
controllernumber = returnControllerNumber(output) controllernumber = returnControllerNumber(output)
if not controllernumber: if not controllernumber:
print '"arcconf" returned no controller, are you sure to have an Adaptec adapter?' print('"arcconf" returned no controller, are you sure to have an Adaptec adapter?')
sys.exit(3) sys.exit(3)
# List controllers # List controllers
if printcontroller: if printcontroller:
if not config.nagios: if not config.nagios:
print "-- Controller informations --" print("-- Controller informations --")
print "-- ID | Model | Status" 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)
@ -258,17 +258,17 @@ if printcontroller:
else: else:
nagiosgoodctrl += 1 nagiosgoodctrl += 1
if not config.nagios: if not config.nagios:
print "c" + str(controllerid - 1) + " | " + controllermodel + " | " + controllerstatus print("c" + str(controllerid - 1) + " | " + controllermodel + " | " + controllerstatus)
controllerid += 1 controllerid += 1
if not config.nagios: if not config.nagios:
print "" print("")
# List arrays # List arrays
if printarray: if printarray:
controllerid = 1 controllerid = 1
if not config.nagios: if not config.nagios:
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID | Type | Size | Status | Task | Progress" 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)
@ -297,23 +297,23 @@ if printarray:
for tasks in tasksinfo: for tasks in tasksinfo:
if int(tasks[0]) == int(arrayid): if int(tasks[0]) == int(arrayid):
if not config.nagios: if not config.nagios:
print "c" + str(controllerid - 1) + "u" + str(arrayid) + " | " + raidtype + " | " + arrayinfo[2] + "G | " + arrayinfo[ print("c" + str(controllerid - 1) + "u" + str(arrayid) + " | " + raidtype + " | " + arrayinfo[2] + "G | " + arrayinfo[
1 1
] + " | " + tasks[1] + " | " + tasks[2] + "%" ] + " | " + tasks[1] + " | " + tasks[2] + "%")
done = True done = True
break break
if done == False: if done == False:
if not config.nagios: if not config.nagios:
print "c" + str(controllerid - 1) + "u" + str(arrayid) + " | " + raidtype + " | " + arrayinfo[2] + "G | " + arrayinfo[1] print("c" + str(controllerid - 1) + "u" + str(arrayid) + " | " + raidtype + " | " + arrayinfo[2] + "G | " + arrayinfo[1])
controllerid += 1 controllerid += 1
if not config.nagios: if not config.nagios:
print "" print("")
# List disks # List disks
controllerid = 1 controllerid = 1
if not config.nagios: if not config.nagios:
print "-- Disks informations" print("-- Disks informations")
print "-- ID | Model | Status" 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)
@ -346,34 +346,34 @@ while controllerid <= controllernumber:
# Matched in members of this array # Matched in members of this array
if disk[0] == member: if disk[0] == member:
if not config.nagios: if not config.nagios:
print "c" + str(controllerid - 1) + "u" + str(arrayid) + "d" + str(memberid) + " | " + disk[2] + " " + disk[3] + " " + disk[ print("c" + str(controllerid - 1) + "u" + str(arrayid) + "d" + str(memberid) + " | " + disk[2] + " " + disk[3] + " " + disk[
4 4
] + " | " + disk[1] ] + " | " + disk[1])
array_member = True array_member = True
memberid += 1 memberid += 1
# Some disks may not be attached to any array (ie: global hot spare) # Some disks may not be attached to any array (ie: global hot spare)
if not array_member: if not array_member:
if not config.nagios: if not config.nagios:
print "c" + str(controllerid - 1) + "uX" + "d" + str(no_array_disk_id) + " | " + disk[2] + " " + disk[3] + " " + disk[4] + " | " + disk[1] print("c" + str(controllerid - 1) + "uX" + "d" + str(no_array_disk_id) + " | " + disk[2] + " " + disk[3] + " " + disk[4] + " | " + disk[1])
no_array_disk_id += 1 no_array_disk_id += 1
controllerid += 1 controllerid += 1
if config.nagios: if config.nagios:
if bad: if bad:
print ( print((
"RAID ERROR - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d" "RAID ERROR - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d"
% (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, nagiosbaddisk) % (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, nagiosbaddisk)
) ))
sys.exit(2) sys.exit(2)
else: else:
print ( print((
"RAID OK - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d" "RAID OK - Controllers OK:%d Bad:%d - Arrays OK:%d Bad:%d - Disks OK:%d Bad:%d"
% (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, nagiosbaddisk) % (nagiosgoodctrl, nagiosbadctrl, nagiosgoodarray, nagiosbadarray, nagiosgooddisk, 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 in a NOT OPTIMAL state.")
print '\nUse "arcconf GETCONFIG [1-9]" to get details.' print('\nUse "arcconf GETCONFIG [1-9]" to get details.')
sys.exit(1) sys.exit(1)

View File

@ -64,7 +64,7 @@ if __name__ == "__main__":
except AttributeError: except AttributeError:
root_or_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 root_or_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
if not root_or_admin: if not root_or_admin:
print "# This script requires Administrator privileges" print("# This script requires Administrator privileges")
sys.exit(5) sys.exit(5)
# Functions # Functions
@ -116,12 +116,12 @@ if megaclipath != None:
pass pass
else: else:
if nagiosmode: if nagiosmode:
print "UNKNOWN - Cannot find " + megaclipath print("UNKNOWN - Cannot find " + megaclipath)
else: else:
print "Cannot find " + megaclipath + "in your PATH. Please install it." print("Cannot find " + megaclipath + "in your PATH. Please install it.")
sys.exit(3) sys.exit(3)
else: else:
print 'Cannot find "MegaCli{64,}", "megacli{64,}", "perccli{64,}" or "storcli{64,}" in your PATH. Please install one of them.' print('Cannot find "MegaCli{64,}", "megacli{64,}", "perccli{64,}" or "storcli{64,}" in your PATH. Please install one of them.')
sys.exit(3) sys.exit(3)
@ -139,7 +139,7 @@ def returnWdthFromArrayCol(glarray, idx):
# Get and cache command output # Get and cache command output
def getOutput(cmd): def getOutput(cmd):
lines = [] lines = []
if Outputs.has_key(cmd): if cmd in Outputs:
dbgprint("Got Cached value: " + str(cmd)) dbgprint("Got Cached value: " + str(cmd))
lines = Outputs[cmd] lines = Outputs[cmd]
else: else:
@ -155,7 +155,7 @@ def getOutput(cmd):
# Get and cache disks, make sure we don't count the same disk twice # Get and cache disks, make sure we don't count the same disk twice
def AddDisk(mytable, disk): def AddDisk(mytable, disk):
lines = [] lines = []
if mytable.has_key(disk): if disk in mytable:
dbgprint("Disk: " + str(disk) + " Already present in Disk Table") dbgprint("Disk: " + str(disk) + " Already present in Disk Table")
return False return False
else: else:
@ -649,7 +649,7 @@ bad = False
if printcontroller: if printcontroller:
if controllernumber: if controllernumber:
if not nagiosmode: if not nagiosmode:
print "-- Controller information --" print("-- Controller information --")
i = 0 i = 0
controllerid = 0 controllerid = 0
@ -668,19 +668,19 @@ if printcontroller:
# Header # Header
if i == 0: if i == 0:
if not nagiosmode: 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: if not nagiosmode:
print hbafmt % (hba[0], hba[1], hba[2], hba[3], hba[4], hba[5]) print(hbafmt % (hba[0], hba[1], hba[2], hba[3], hba[4], hba[5]))
i += 1 i += 1
if not nagiosmode: if not nagiosmode:
print "" print("")
else: else:
print "No MegaRAID or PERC adapter detected on your system!" print("No MegaRAID or PERC adapter detected on your system!")
exit(1) exit(1)
if printarray: if printarray:
if not nagiosmode: if not nagiosmode:
print "-- Array information --" print("-- Array information --")
controllerid = 0 controllerid = 0
pcipath = "" pcipath = ""
@ -768,9 +768,9 @@ if printarray:
# Header # Header
if i == 0: if i == 0:
if not nagiosmode: 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: if not nagiosmode:
print ldfmt % ( print(ldfmt % (
arrayinfo[0], arrayinfo[0],
arrayinfo[1], arrayinfo[1],
arrayinfo[2], arrayinfo[2],
@ -781,7 +781,7 @@ if printarray:
arrayinfo[7], arrayinfo[7],
arrayinfo[8], arrayinfo[8],
arrayinfo[9], arrayinfo[9],
) ))
dbgprint("Array state : LD " + arrayinfo[0] + ", status : " + arrayinfo[6]) dbgprint("Array state : LD " + arrayinfo[0] + ", status : " + arrayinfo[6])
if arrayinfo[6] not in ["Optimal", "N/A"]: if arrayinfo[6] not in ["Optimal", "N/A"]:
bad = True bad = True
@ -792,7 +792,7 @@ if printarray:
i += 1 i += 1
controllerid += 1 controllerid += 1
if not nagiosmode: if not nagiosmode:
print "" print("")
controllerid = 0 controllerid = 0
while controllerid < controllernumber: while controllerid < controllernumber:
@ -803,7 +803,7 @@ while controllerid < controllernumber:
if totaldrivenumber: if totaldrivenumber:
if not nagiosmode: if not nagiosmode:
print "-- Disk information --" print("-- Disk information --")
i = 0 i = 0
dlen = 0 dlen = 0
@ -859,10 +859,10 @@ if totaldrivenumber:
# Header # Header
if i == 0: if i == 0:
if not nagiosmode: if not nagiosmode:
print drvfmt % ("-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI ID") print(drvfmt % ("-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI ID"))
# Drive information # Drive information
if not nagiosmode: if not nagiosmode:
print drvfmt % ( print(drvfmt % (
str("c" + str(controllerid) + "u" + array[0] + "p" + array[1]), # c0p0 str("c" + str(controllerid) + "u" + array[0] + "p" + array[1]), # c0p0
array[2], # HDD/SDD array[2], # HDD/SDD
array[3], # Model Information (Variable len) array[3], # Model Information (Variable len)
@ -872,11 +872,11 @@ if totaldrivenumber:
array[7], # Temp array[7], # Temp
str("[" + array[8] + ":" + array[9] + "]"), # Slot ID str("[" + array[8] + ":" + array[9] + "]"), # Slot ID
array[10], array[10],
) # LSI ID )) # LSI ID
i = i + 1 i = i + 1
controllerid += 1 controllerid += 1
if not nagiosmode: if not nagiosmode:
print "" print("")
controllerid = 0 controllerid = 0
totalconfdrivenumber = 0 totalconfdrivenumber = 0
@ -906,7 +906,7 @@ dbgprint("Total Unconfigured Drives : " + str(totalunconfdrivenumber))
if totalunconfdrivenumber: if totalunconfdrivenumber:
if not nagiosmode: if not nagiosmode:
print "-- Unconfigured Disk information --" print("-- Unconfigured Disk information --")
controllerid = 0 controllerid = 0
pcipath = "" pcipath = ""
@ -966,10 +966,10 @@ if totalunconfdrivenumber:
# Header # Header
if i == 0: if i == 0:
if not nagiosmode: if not nagiosmode:
print drvfmt % ("-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI ID", "Path") print(drvfmt % ("-- ID", "Type", "Drive Model", "Size", "Status", "Speed", "Temp", "Slot ID", "LSI ID", "Path"))
# Drive information # Drive information
if not nagiosmode: if not nagiosmode:
print drvfmt % ( print(drvfmt % (
str("c" + str(controllerid) + "uXpY"), # cXpY str("c" + str(controllerid) + "uXpY"), # cXpY
array[0], # HDD/SDD array[0], # HDD/SDD
array[1], # Model Information (Variable len) array[1], # Model Information (Variable len)
@ -980,11 +980,11 @@ if totalunconfdrivenumber:
str("[" + array[6] + ":" + array[7] + "]"), # Slot ID str("[" + array[6] + ":" + array[7] + "]"), # Slot ID
array[8], # LSI ID array[8], # LSI ID
array[9], array[9],
) # OS path, if any )) # OS path, if any
i += 1 i += 1
controllerid += 1 controllerid += 1
if not nagiosmode: if not nagiosmode:
print "" print("")
if debugmode: if debugmode:
dbgprint("Printing Outputs[][]") dbgprint("Printing Outputs[][]")
@ -1002,21 +1002,21 @@ if debugmode:
if nagiosmode: if nagiosmode:
if bad: if bad:
print "RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk nagiosbaddisk
) ))
sys.exit(2) sys.exit(2)
else: else:
print "RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk nagiosbaddisk
) ))
else: else:
if bad: if bad:
# DO NOT MODIFY OUTPUT BELOW # DO NOT MODIFY OUTPUT BELOW
# Scripts may relies on it # Scripts may relies on it
# https://github.com/eLvErDe/hwraid/issues/99 # https://github.com/eLvErDe/hwraid/issues/99
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.")
print "RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk nagiosbaddisk
) ))
sys.exit(1) sys.exit(1)

View File

@ -5,7 +5,7 @@ import re
import sys import sys
if len(sys.argv) > 2: if len(sys.argv) > 2:
print "Usage: megaide-status [-d]" print("Usage: megaide-status [-d]")
sys.exit(1) sys.exit(1)
printarray = True printarray = True
@ -15,7 +15,7 @@ if len(sys.argv) > 1:
printarray = False printarray = False
printcontroller = False printcontroller = False
else: else:
print "Usage: megaide-status [-d]" print("Usage: megaide-status [-d]")
sys.exit(1) sys.exit(1)
@ -88,32 +88,32 @@ bad = False
if printarray: if printarray:
controllerid = 0 controllerid = 0
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID | Type | Size | Status" print("-- ID | Type | Size | Status")
while controllerid <= controllernumber: while controllerid <= controllernumber:
arrayid = 0 arrayid = 0
arraynumber = returnArrayNumber(controllerid) arraynumber = returnArrayNumber(controllerid)
while arrayid <= arraynumber: while arrayid <= arraynumber:
arrayinfo = returnArrayInfo(controllerid, arrayid) arrayinfo = returnArrayInfo(controllerid, arrayid)
print arrayinfo[0] + " | " + arrayinfo[1] + " | " + arrayinfo[2] + " | " + arrayinfo[3] print(arrayinfo[0] + " | " + arrayinfo[1] + " | " + arrayinfo[2] + " | " + arrayinfo[3])
arrayid += 1 arrayid += 1
if not arrayinfo[3] == "ONLINE": if not arrayinfo[3] == "ONLINE":
bad = True bad = True
controllerid += 1 controllerid += 1
print "" print("")
print "-- Disks informations" print("-- Disks informations")
print "-- ID | Model | Status" print("-- ID | Model | Status")
controllerid = 0 controllerid = 0
while controllerid <= controllernumber: while controllerid <= controllernumber:
diskinfo = returnDiskInfo() diskinfo = returnDiskInfo()
for disk in diskinfo: for disk in diskinfo:
print disk[0] + " | " + disk[2] + " | " + disk[1] print(disk[0] + " | " + disk[2] + " | " + disk[1])
if not disk[1] == "ONLINE": if not disk[1] == "ONLINE":
bad = True bad = True
controllerid += 1 controllerid += 1
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)

View File

@ -7,7 +7,7 @@ import sys
binarypath = "/usr/sbin/megactl" binarypath = "/usr/sbin/megactl"
if len(sys.argv) > 2: if len(sys.argv) > 2:
print "Usage: megaraid-status [-d]" print("Usage: megaraid-status [-d]")
sys.exit(1) sys.exit(1)
printarray = True printarray = True
@ -15,7 +15,7 @@ if len(sys.argv) > 1:
if sys.argv[1] == "-d": if sys.argv[1] == "-d":
printarray = False printarray = False
else: else:
print "Usage: megaraid-status [-d]" print("Usage: megaraid-status [-d]")
sys.exit(1) sys.exit(1)
# Check binary exists (and +x), if not print an error message # Check binary exists (and +x), if not print an error message
@ -77,21 +77,21 @@ disklist = returnDiskList(output)
arraylist = returnArrayList(output) arraylist = returnArrayList(output)
if printarray: if printarray:
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID | Type | Size | Status" print("-- ID | Type | Size | Status")
for array in arraylist: for array in arraylist:
print array[0] + " | " + array[2] + " " + array[3] + " | " + array[1] + " | " + array[-1] print(array[0] + " | " + array[2] + " " + array[3] + " | " + array[1] + " | " + array[-1])
print "" print("")
print "-- Disks informations" print("-- Disks informations")
print "-- ID | Model | Status | Warnings" print("-- ID | Model | Status | Warnings")
for disk in disklist: for disk in disklist:
# Check if there's some smart non critical warnings # Check if there's some smart non critical warnings
if re.match(r"^errs:.*$", disk[-2]): if re.match(r"^errs:.*$", disk[-2]):
# Some disk may have vendor or model containing spaces # Some disk may have vendor or model containing spaces
print disk[0] + " | " + " ".join(disk[1:-3]) + " | " + disk[-1] + " | " + disk[-2] print(disk[0] + " | " + " ".join(disk[1:-3]) + " | " + disk[-1] + " | " + disk[-2])
else: else:
print disk[0] + " | " + " ".join(disk[1:-2]) + " | " + disk[-1] print(disk[0] + " | " + " ".join(disk[1:-2]) + " | " + disk[-1])
# Check if there's a bad disk # Check if there's a bad disk
bad = False bad = False
@ -104,5 +104,5 @@ for disk in disklist:
bad = True bad = True
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)

View File

@ -7,7 +7,7 @@ import sys
binarypath = "/usr/sbin/megasasctl" binarypath = "/usr/sbin/megasasctl"
if len(sys.argv) > 2: if len(sys.argv) > 2:
print "Usage: megaraidsas-status [-d]" print("Usage: megaraidsas-status [-d]")
sys.exit(1) sys.exit(1)
printarray = True printarray = True
@ -15,7 +15,7 @@ if len(sys.argv) > 1:
if sys.argv[1] == "-d": if sys.argv[1] == "-d":
printarray = False printarray = False
else: else:
print "Usage: megaraidsas-status [-d]" print("Usage: megaraidsas-status [-d]")
sys.exit(1) sys.exit(1)
# Check binary exists (and +x), if not print an error message # Check binary exists (and +x), if not print an error message
@ -77,21 +77,21 @@ disklist = returnDiskList(output)
arraylist = returnArrayList(output) arraylist = returnArrayList(output)
if printarray: if printarray:
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID | Type | Size | Status" print("-- ID | Type | Size | Status")
for array in arraylist: for array in arraylist:
print array[0] + " | " + array[2] + " " + array[3] + " | " + array[1] + " | " + array[-1] print(array[0] + " | " + array[2] + " " + array[3] + " | " + array[1] + " | " + array[-1])
print "" print("")
print "-- Disks informations" print("-- Disks informations")
print "-- ID | Model | Status | Warnings" print("-- ID | Model | Status | Warnings")
for disk in disklist: for disk in disklist:
# Check if there's some smart non critical warnings # Check if there's some smart non critical warnings
if re.match(r"^errs:.*$", disk[-2]): if re.match(r"^errs:.*$", disk[-2]):
# Some disk may have vendor or model containing spaces # Some disk may have vendor or model containing spaces
print disk[0] + " | " + " ".join(disk[1:-3]) + " | " + disk[-1] + " | " + disk[-2] print(disk[0] + " | " + " ".join(disk[1:-3]) + " | " + disk[-1] + " | " + disk[-2])
else: else:
print disk[0] + " | " + " ".join(disk[1:-2]) + " | " + disk[-1] print(disk[0] + " | " + " ".join(disk[1:-2]) + " | " + disk[-1])
# Check if there's a bad disk # Check if there's a bad disk
bad = False bad = False
@ -104,5 +104,5 @@ for disk in disklist:
bad = True bad = True
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)

View File

@ -6,11 +6,11 @@ import sys
binarypath = "/usr/sbin/sas2ircu" binarypath = "/usr/sbin/sas2ircu"
if not os.path.isfile(binarypath): if not os.path.isfile(binarypath):
print "sas2ircu is not available in expected location: {}".format(binarypath) print("sas2ircu is not available in expected location: {}".format(binarypath))
sys.exit(1) sys.exit(1)
if len(sys.argv) > 2: if len(sys.argv) > 2:
print "Usage: sas2ircu-status [--nagios]" print("Usage: sas2ircu-status [--nagios]")
sys.exit(1) sys.exit(1)
nagiosmode = False nagiosmode = False
@ -24,7 +24,7 @@ if len(sys.argv) > 1:
if sys.argv[1] == "--nagios": if sys.argv[1] == "--nagios":
nagiosmode = True nagiosmode = True
else: else:
print "Usage: sas2ircu-status [--nagios]" print("Usage: sas2ircu-status [--nagios]")
sys.exit(1) sys.exit(1)
bad = False bad = False
@ -136,15 +136,15 @@ def getDiskList(ctrlnmbr):
ctrls = getCtrlList() ctrls = getCtrlList()
arraymap = {} arraymap = {}
if not nagiosmode: if not nagiosmode:
print "-- Controller informations --" print("-- Controller informations --")
print "-- ID | Model" print("-- ID | Model")
for ctrl in ctrls: for ctrl in ctrls:
print "c" + str(ctrl[0]) + " | " + ctrl[1] print("c" + str(ctrl[0]) + " | " + ctrl[1])
print "" print("")
if not nagiosmode: if not nagiosmode:
print "-- Arrays informations --" print("-- Arrays informations --")
print "-- ID | Type | Size | Status" print("-- ID | Type | Size | Status")
for ctrl in ctrls: for ctrl in ctrls:
for array in getArrayList(ctrl[0]): for array in getArrayList(ctrl[0]):
arraymap[ctrl[0]] = array arraymap[ctrl[0]] = array
@ -154,13 +154,13 @@ for ctrl in ctrls:
else: else:
nagiosgoodarray = nagiosgoodarray + 1 nagiosgoodarray = nagiosgoodarray + 1
if not nagiosmode: if not nagiosmode:
print "c" + str(ctrl[0]) + "u" + str(array[0]) + " | " + array[1] + " | " + array[2] + " | " + array[3] print("c" + str(ctrl[0]) + "u" + str(array[0]) + " | " + array[1] + " | " + array[2] + " | " + array[3])
if not nagiosmode: if not nagiosmode:
print "" print("")
if not nagiosmode: if not nagiosmode:
print "-- Disks informations" print("-- Disks informations")
print "-- ID | Model | Status" print("-- ID | Model | Status")
for ctrl in ctrls: for ctrl in ctrls:
for disk in getDiskList(ctrl[0]): for disk in getDiskList(ctrl[0]):
# Compare disk enc/slot to array's ones # Compare disk enc/slot to array's ones
@ -173,19 +173,19 @@ for ctrl in ctrls:
else: else:
nagiosgooddisk = nagiosgooddisk + 1 nagiosgooddisk = nagiosgooddisk + 1
if not nagiosmode: if not nagiosmode:
print "c" + str(ctrl[0]) + "u" + str(array[0]) + "p" + str(disk[0]) + " | " + disk[2] + " (" + disk[3] + ") | " + disk[1] print("c" + str(ctrl[0]) + "u" + str(array[0]) + "p" + str(disk[0]) + " | " + disk[2] + " (" + disk[3] + ") | " + disk[1])
if nagiosmode: if nagiosmode:
if bad: if bad:
print "RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID ERROR - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk nagiosbaddisk
) ))
sys.exit(2) sys.exit(2)
else: else:
print "RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str( print("RAID OK - Arrays: OK:" + str(nagiosgoodarray) + " Bad:" + str(nagiosbadarray) + " - Disks: OK:" + str(nagiosgooddisk) + " Bad:" + str(
nagiosbaddisk 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 in a NOT OPTIMAL state.")
sys.exit(1) sys.exit(1)