Skip to content

Commit

Permalink
add python3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fadnincx committed Mar 22, 2022
1 parent 8ab202e commit fa2bedd
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 234 deletions.
15 changes: 7 additions & 8 deletions plugins/Check_Array_Availibility.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
loginUrl = serverUrl + "/devmgr/utils"
stat = 0
logging.basicConfig(format='%(asctime)s - %(name)s : %(message)s', filename='/tmp/nagios-python.log', level=logging.DEBUG)
handler = RotatingFileHandler('/tmp/nagios-python.log', maxBytes=SANtricityStorage.maxbytes,
backupCount=20)
handler = RotatingFileHandler('/tmp/nagios-python.log', maxBytes=SANtricityStorage.maxbytes, backupCount=20)
logger = logging.getLogger("STORAGEPOOL")
logger.addHandler(handler)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -73,7 +72,7 @@ def getArrayInformation():
break
elif hostipaddress == "":
arrayId = row[headerList.index("arrayId")]
if currentArrayId <> arrayId and firstArray == False:
if currentArrayId != arrayId and firstArray == False:
strResultData += get_array_availibility(sessionid, currentArrayId)
else:
firstArray = False
Expand All @@ -92,7 +91,7 @@ def getArrayInformation():

try:
if len(sys.argv) < 3:
print "STATUS UNKNOWN - Required parameters not set"
print("STATUS UNKNOWN - Required parameters not set")
sys.exit(3)
else:
nextelearg = False
Expand Down Expand Up @@ -123,7 +122,7 @@ def getArrayInformation():
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
else:
print "Invalid arguments passed"
print("Invalid arguments passed")
sys.exit(3)


Expand Down Expand Up @@ -156,10 +155,10 @@ def getArrayInformation():
elif stat == 2:
str = "Critical - Array is down|" + str

print str
print(str)
sys.exit(stat)

except Exception, err:
print "STATUS UNKNOWN"
except Exception as err:
print("STATUS UNKNOWN")
logger.error("Error in Storage Pool Status", exc_info=True)
sys.exit(3)
24 changes: 12 additions & 12 deletions plugins/Check_Physical_Comp_Status.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
listmode = ["RBCON", "EBIOM", "TRAY", "BATT", "FAN", "PSU", "DDS", "ARRY","ALL"]
msglist = {"BATT": "Batteries", "": "Physical Components", "RBCON": "RBOD Controllers", "EBIOM": "EBOD IOMs",
"TRAY": "Trays ", "FAN": "Fans", "PSU": "Power Supply Units", "DDS": "Disk Drives", "ARRY": "Arrays"}
logging.basicConfig(format='%(asctime)s - %(name)s : %(message)s', filename='/tmp//tmp/nagios-python.log', level=logging.DEBUG)
logging.basicConfig(format='%(asctime)s - %(name)s : %(message)s', filename='/tmp/nagios-python.log', level=logging.DEBUG)
handler = RotatingFileHandler('/tmp/nagios-python.log', maxBytes=SANtricityStorage.maxbytes,
backupCount=20)
logger = logging.getLogger("PHYCOMPSTAT")
Expand All @@ -35,7 +35,7 @@ def get_phy_comp_stat_by_array(arrayid, sessionid, arrinfo, controllername):
resultdata = get_array_status(sessionid, arrayid)
strOutPut += resultdata["strOutPut"]
if stat == 2:
print "Critical - Array is down, no other status can be fetched"
print("Critical - Array is down, no other status can be fetched")
sys.exit(2)

resultdata = {}
Expand Down Expand Up @@ -237,8 +237,8 @@ def get_battery_status(data):
stat = 2
optimal = 0
elif (ele["status"] == "learning" and stat <2):
stat = 1
optimal = 0
stat = 1
optimal = 0
else:
optimal = 1
stroutput += "\nSlot : " + str(ele["physicalLocation"]["slot"]) + ", Status : " + ele[
Expand Down Expand Up @@ -384,7 +384,7 @@ def getphysicalcomptstatus():

arrayId = row[headerList.index("arrayId")]
arrayinfo[arrayId] = {"arrayName": row[headerList.index("arrayName")]}
if currentarrayid <> arrayId and firstarray == False:
if currentarrayid != arrayId and firstarray == False:

lstresult.append(get_phy_comp_stat_by_array(currentarrayid, sessionid, arrayinfo, controllername))
controllername = {}
Expand Down Expand Up @@ -439,7 +439,7 @@ def getphysicalcomptstatus():
'''
try:
if len(sys.argv) < 2:
print "STATUS UNKNOWN - Required parameters not set"
print("STATUS UNKNOWN - Required parameters not set")
sys.exit(3)
else:
nextelearg = False
Expand Down Expand Up @@ -474,7 +474,7 @@ def getphysicalcomptstatus():
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
else:
print "Invalid arguments passed"
print("Invalid arguments passed")
logging.error("Invalid arguments passed",exc_info=True)
sys.exit(3)

Expand All @@ -486,7 +486,7 @@ def getphysicalcomptstatus():

loginUrl = serverUrl + "/devmgr/utils"
else:
print "STATUS UNKNOWN- Webproxy must be set"
print("STATUS UNKNOWN- Webproxy must be set")
logging.error("Webproxy not set",exc_info=True)
sys.exit(3)

Expand All @@ -497,7 +497,7 @@ def getphysicalcomptstatus():
try:
index = listmode.index(mode);
except:
print "STATUS UNKNOWN-Incorrect value for mode"
print("STATUS UNKNOWN-Incorrect value for mode")
sys.exit(3)
else:
mode =""
Expand All @@ -518,9 +518,9 @@ def getphysicalcomptstatus():
logger.debug("Mode:" + argmap["mode"])

str = getphysicalcomptstatus()
print str
print(str)
sys.exit(stat)
except Exception, err:
except Exception as err:
logger.error("Error inside get volume stat by controller", exc_info=True)
print "STATUS UNKNOWN"
print("STATUS UNKNOWN")
sys.exit(3)
19 changes: 9 additions & 10 deletions plugins/Check_Physical_Comp_Temp.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def get_phy_comp_temprature(arrayid,sessionid,arrayinfo):
crutype=ele["rtrAttributes"]["parentCru"]["type"]

if crutype in ["supportCru","controller","esm"] and ele["status"] !="optimal":

stat =2
if crutype =="supportCru":
strpowesupp+="\nSlot : "+str(ele["physicalLocation"]["slot"]) +" Status : "+ele["status"]
Expand Down Expand Up @@ -104,7 +103,7 @@ def getphysicalcomtemprature():
elif hostipaddress == "":
arrayid=row[headerList.index("arrayId")]
arrayinfo[arrayid]={"arrayName":row[headerList.index("arrayName")]}
if currentarrayid <> arrayid and firstarray ==False:
if currentarrayid != arrayid and firstarray ==False:
lstresult.append(get_phy_comp_temprature(currentarrayid,sessionid,arrayinfo))
else:
firstarray =False
Expand Down Expand Up @@ -145,7 +144,7 @@ def getphysicalcomtemprature():

try:
if len(sys.argv) < 8:
print "STATUS UNKNOWN - Required parameters not set"
print("STATUS UNKNOWN - Required parameters not set")
sys.exit(3)
else:
nextelearg=False
Expand Down Expand Up @@ -182,7 +181,7 @@ def getphysicalcomtemprature():
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
else:
print "STATUS UNKNOWN - Invalid arguments passed"
print("STATUS UNKNOWN - Invalid arguments passed")
sys.exit(3)


Expand All @@ -197,7 +196,7 @@ def getphysicalcomtemprature():
warning =float(argmap["warning"])
except Exception:
logger.error("Error in physical component status",exc_info=True)
print "STATUS UNKNOWN - Warning threshold must be numeric"
print("STATUS UNKNOWN - Warning threshold must be numeric")
sys.exit(3)

try:
Expand All @@ -206,7 +205,7 @@ def getphysicalcomtemprature():

except Exception:
logger.error("Error in physical component status",exc_info=True)
print "STATUS UNKNOWN - Critical threshold must be numeric"
print("STATUS UNKNOWN - Critical threshold must be numeric")
sys.exit(3)

if argmap["username"] !="":
Expand All @@ -218,7 +217,7 @@ def getphysicalcomtemprature():
password = argmap["password"]

if warning >= critical:
print "STATUS UNKNOWN - Incorrect value for warning and critical thresold, warning must be less than critical"
print("STATUS UNKNOWN - Incorrect value for warning and critical thresold, warning must be less than critical")
sys.exit(3)

if argmap["hostIp"] != "127.0.0.1":
Expand All @@ -228,9 +227,9 @@ def getphysicalcomtemprature():
logger.debug("Critical Temp:"+argmap["critical"])

str=getphysicalcomtemprature()
print str
print(str)
sys.exit(stat)
except Exception,err:
except Exception as err:
logger.error("Error in Check_Physical_Comp_Temp",exc_info=True)
print "STATUS UNKNOWN"
print("STATUS UNKNOWN")
sys.exit(3)
28 changes: 14 additions & 14 deletions plugins/Check_SANtricity_Drive_Stat.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_drive_state():
sessionid= SANtricityStorage.login(loginUrl,username,password)
SANtricityStorage.getStorageSystemDetails(urlToServer,sessionid,timewindow)
file = SANtricityStorage.getStoragePath() + "/controller.csv"
fileforread=open(file,"rb")
fileforread=open(file,"r")
csvreader=csv.reader(fileforread,delimiter=",")
firstline=True
currentarrayid=""
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_drive_state():
elif hostipaddress == "":
arrayid=row[headerList.index("arrayId")]
arrayinfo[arrayid]={"arrayName":row[headerList.index("arrayName")]}
if currentarrayid <> arrayid and firstArray == False:
if currentarrayid != arrayid and firstArray == False:
lstResult.append(get_drive_detail(currentarrayid,sessionid,arrayinfo))
controllername={}
controllername[row[headerList.index("controllerRef")]]=row[headerList.index("controllerLabel")]
Expand Down Expand Up @@ -154,7 +154,7 @@ def get_drive_state():

try:
if len(sys.argv) < 10:
print "STATUS UNKNOWN - Required parameters not set"
print("STATUS UNKNOWN - Required parameters not set")
sys.exit(3)
else:
nextelearg=False
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_drive_state():
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
else:
print "Invalid arguments passed"
print("Invalid arguments passed")
sys.exit(3)


Expand All @@ -213,34 +213,34 @@ def get_drive_state():
try:
index=listMode[mode];
except:
print "STATUS UNKNOWN - Incorrect value for mode"
print("STATUS UNKNOWN - Incorrect value for mode")
sys.exit(3)


if argmap["r"] !="":

range= argmap["r"]
if range !="low" and range !="high":
print "STATUS UNKNOW - Incorrect value for range selector. It must be either \"low\" or \"high\". "
print("STATUS UNKNOW - Incorrect value for range selector. It must be either \"low\" or \"high\". ")
sys.exit(3)

try:
low=float(argmap["warning"])
except Exception,err:
print "STATUS UNKNOWN - Warning threshold must be numeric"
except Exception as err:
print("STATUS UNKNOWN - Warning threshold must be numeric")
sys.exit(3)



try:
high=float(argmap["critical"])
except Exception,err:
print "STATUS UNKNOWN - Critical threshold must be numeric"
except Exception as err:
print("STATUS UNKNOWN - Critical threshold must be numeric")
sys.exit(3)


if (range == "high" and low >=high) or (range =="low" and low <= high):
print 'STATUS UNKNOWN - Incorrect value for warning and critical threshold'
print('STATUS UNKNOWN - Incorrect value for warning and critical threshold')
sys.exit(3)


Expand All @@ -263,10 +263,10 @@ def get_drive_state():
logger.debug("Mode:"+mode)
logger.debug("Range:"+range)
str=get_drive_state()
print str
print(str)
sys.exit(stat)
except Exception,err:
except Exception as err:
logging.error("Error in main block",exc_info=True)

print "STATUS UNKNOWN"
print("STATUS UNKNOWN")
sys.exit(3)
22 changes: 11 additions & 11 deletions plugins/Check_SANtricity_Logical_Comp_Status.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_logical_comp_stat_by_array(arrayid, sessionid, arrinfo, controllername):
strOutPut = "\nArray Name : " + arrinfo[arrayid]["arrayName"]

if stat == 2:
print "Critical - Array is down, no other status can be fetched"
print("Critical - Array is down, no other status can be fetched")
sys.exit(2)

resultdata = {}
Expand Down Expand Up @@ -460,7 +460,7 @@ def getlogicalcomptstatus():
sessionid = SANtricityStorage.login(loginUrl,username,password)
SANtricityStorage.getStorageSystemDetails(urlToServer, sessionid, SANtricityStorage.getTime())
file = SANtricityStorage.getStoragePath() + "/controller.csv"
fileforread = open(file, "rb")
fileforread = open(file, "r")
csvreader = csv.reader(fileforread, delimiter=",")
firstline = True
currentarrayid = ""
Expand Down Expand Up @@ -489,7 +489,7 @@ def getlogicalcomptstatus():

arrayId = row[headerList.index("arrayId")]
arrayinfo[arrayId] = {"arrayName": row[headerList.index("arrayName")]}
if currentarrayid <> arrayId and firstarray == False:
if currentarrayid != arrayId and firstarray == False:

lstresult.append(
get_logical_comp_stat_by_array(currentarrayid, sessionid, arrayinfo, controllername))
Expand Down Expand Up @@ -549,7 +549,7 @@ def getlogicalcomptstatus():
'''
try:
if len(sys.argv) < 2:
print "STATUS UNKNOWN - Required parameters not set"
print("STATUS UNKNOWN - Required parameters not set")
sys.exit(3)
else:
nextelearg = False
Expand Down Expand Up @@ -579,12 +579,12 @@ def getlogicalcomptstatus():
argname="password"
elif element == "-debug":

# logging.basicConfig(format='%(asctime)s - %(name)s : %(message)s',filename='/tmp/nagios-python.log',level=logging.DEBUG)
# logging.basicConfig(format='%(asctime)s - %(name)s : %(message)s',filename='nagios-python.log',level=logging.DEBUG)
logger = logging.getLogger("LOGICALCOMPSTAT")
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
else:
print "Invalid arguments passed"
print("Invalid arguments passed")
sys.exit(3)


Expand All @@ -595,7 +595,7 @@ def getlogicalcomptstatus():

loginUrl = serverUrl + "/devmgr/utils"
else:
print "STATUS UNKNOWN- Webproxy must be set"
print("STATUS UNKNOWN- Webproxy must be set")
sys.exit(3)


Expand All @@ -605,7 +605,7 @@ def getlogicalcomptstatus():
try:
index = listmode.index(mode);
except:
print "STATUS UNKNOWN-Incorrect value for mode"
print("STATUS UNKNOWN-Incorrect value for mode")
sys.exit(3)
else:
mode =""
Expand All @@ -625,9 +625,9 @@ def getlogicalcomptstatus():
logger.debug("Mode:" + argmap["mode"])

str = getlogicalcomptstatus()
print str
print(str)
sys.exit(stat)
except Exception, err:
except Exception as err:
logger.error("Error inside get volume stat by controller", exc_info=True)
print "STATUS UNKNOWN"
print("STATUS UNKNOWN")
sys.exit(3)
Loading

0 comments on commit fa2bedd

Please sign in to comment.