Re-indent

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

View File

@ -8,34 +8,34 @@ from argparse import ArgumentParser
# Argument parser # Argument parser
# My own ArgumentParser with single-line stdout output and unknown state Nagios retcode # My own ArgumentParser with single-line stdout output and unknown state Nagios retcode
class NagiosArgumentParser(ArgumentParser): class NagiosArgumentParser(ArgumentParser):
def error(self, message): def error(self, message):
sys.stdout.write('UNKNOWN: Bad arguments (see --help): %s\n' % message) sys.stdout.write('UNKNOWN: Bad arguments (see --help): %s\n' % message)
sys.exit(3) sys.exit(3)
def parse_args(): def parse_args():
parser = NagiosArgumentParser(description='Adaptec AACRAID status script') parser = NagiosArgumentParser(description='Adaptec AACRAID status script')
parser.add_argument('-d', '--disks-only', action="store_true", help='Only disply disk statuses') parser.add_argument('-d', '--disks-only', action="store_true", help='Only disply disk statuses')
parser.add_argument('-n', '--nagios', action="store_true", help='Use Nagios-like output and return code') parser.add_argument('-n', '--nagios', action="store_true", help='Use Nagios-like output and return code')
return parser.parse_args() return parser.parse_args()
def which(program): def which(program):
fpath, fname = os.path.split(program) fpath, fname = os.path.split(program)
if fpath: if fpath:
if is_exe(program): if is_exe(program):
return program return program
else: else:
# Add some defaults # Add some defaults
os.environ["PATH"] += os.pathsep + '/usr/StorMan/arcconf' os.environ["PATH"] += os.pathsep + '/usr/StorMan/arcconf'
os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(sys.argv[0])) os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(sys.argv[0]))
for path in os.environ["PATH"].split(os.pathsep): for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"') path = path.strip('"')
exe_file = os.path.join(path, program) exe_file = os.path.join(path, program)
if is_exe(exe_file): if is_exe(exe_file):
return exe_file return exe_file
return None return None
def is_exe(fpath): def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
# Get command output # Get command output
def getOutput(cmd): def getOutput(cmd):
@ -150,33 +150,42 @@ def returnDisksInfo(output,controllerid):
config = parse_args() config = parse_args()
if config.disks_only: if config.disks_only:
printarray = False printarray = False
printcontroller = False printcontroller = False
else: else:
printarray = True printarray = True
printcontroller = True printcontroller = True
nagiosoutput=''
nagiosgoodctrl = 0
nagiosbadctrl = 0
nagiosctrlbadarray = 0
nagiosgoodarray = 0
nagiosbadarray = 0
nagiosgooddisk = 0
nagiosbaddisk = 0
bad = False bad = False
# Find arcconf # Find arcconf
for arcconfbin in "arcconf","arcconf.exe": for arcconfbin in "arcconf","arcconf.exe":
arcconfpath = which(arcconfbin) arcconfpath = which(arcconfbin)
if (arcconfpath != None): if (arcconfpath != None):
break break
# Check binary exists (and +x), if not print an error message # Check binary exists (and +x), if not print an error message
if (arcconfpath != None): if (arcconfpath != None):
if is_exe(arcconfpath): if is_exe(arcconfpath):
pass pass
else: else:
if nagiosmode: 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)
cmd = '"%s" GETVERSION' % arcconfpath cmd = '"%s" GETVERSION' % arcconfpath