mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 10:23:46 +01:00
check_hpacucli - fix tab indentation
This commit is contained in:
parent
3cf6cb7f2d
commit
f06667b55d
@ -18,7 +18,7 @@
|
|||||||
# About this script
|
# About this script
|
||||||
#
|
#
|
||||||
# This script will check the status of Smart Array Raid Controller
|
# This script will check the status of Smart Array Raid Controller
|
||||||
# You will need the hpacucli binary in path (/usr/sbin/hpacucli is a good place)
|
# You need the hpacucli binary in path (/usr/sbin/hpacucli is a good place)
|
||||||
# hpacucli comes with the Proliant Support Pack (PSP) from HP
|
# hpacucli comes with the Proliant Support Pack (PSP) from HP
|
||||||
|
|
||||||
debugging = False
|
debugging = False
|
||||||
@ -82,249 +82,250 @@ def debug( debugtext ):
|
|||||||
print debugtext
|
print debugtext
|
||||||
|
|
||||||
|
|
||||||
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
|
|
||||||
def runCommand(command):
|
def runCommand(command):
|
||||||
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
|
""" Runs command from the shell prompt. Exit Nagios style if unsuccessful"""
|
||||||
stdout, stderr = proc.communicate('through stdin to stdout')
|
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
|
||||||
if proc.returncode > 0:
|
stdout, stderr = proc.communicate('through stdin to stdout')
|
||||||
print "Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)
|
if proc.returncode > 0:
|
||||||
|
print "Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)
|
||||||
debug("results: %s" % (stdout.strip() ) )
|
debug("results: %s" % (stdout.strip() ) )
|
||||||
if proc.returncode == 127: # File not found, lets print path
|
if proc.returncode == 127: # File not found, lets print path
|
||||||
path=getenv("PATH")
|
path=getenv("PATH")
|
||||||
print "Check if your path is correct %s" % (path)
|
print "Check if your path is correct %s" % (path)
|
||||||
if stderr.find('Password:') == 0 and command.find('sudo') == 0:
|
if stderr.find('Password:') == 0 and command.find('sudo') == 0:
|
||||||
print "Check if user is in the sudoers file"
|
print "Check if user is in the sudoers file"
|
||||||
if stderr.find('sorry, you must have a tty to run sudo') == 0 and command.find('sudo') == 0:
|
if stderr.find('sorry, you must have a tty to run sudo') == 0 and command.find('sudo') == 0:
|
||||||
print "Please remove 'requiretty' from /etc/sudoers"
|
print "Please remove 'requiretty' from /etc/sudoers"
|
||||||
exit(unknown)
|
exit(unknown)
|
||||||
else:
|
else:
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
def end():
|
def end():
|
||||||
global summary
|
global summary
|
||||||
global longserviceoutput
|
global longserviceoutput
|
||||||
global perfdata
|
global perfdata
|
||||||
global nagios_status
|
global nagios_status
|
||||||
print "%s - %s | %s" % (state[nagios_status], summary,perfdata)
|
print "%s - %s | %s" % (state[nagios_status], summary,perfdata)
|
||||||
print longserviceoutput
|
print longserviceoutput
|
||||||
if nagios_status < 0: nagios_status = unknown
|
if nagios_status < 0: nagios_status = unknown
|
||||||
exit(nagios_status)
|
exit(nagios_status)
|
||||||
|
|
||||||
def add_perfdata(text):
|
def add_perfdata(text):
|
||||||
global perfdata
|
global perfdata
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
perfdata = perfdata + " %s " % (text)
|
perfdata = perfdata + " %s " % (text)
|
||||||
|
|
||||||
def add_long(text):
|
def add_long(text):
|
||||||
global longserviceoutput
|
global longserviceoutput
|
||||||
longserviceoutput = longserviceoutput + text + '\n'
|
longserviceoutput = longserviceoutput + text + '\n'
|
||||||
|
|
||||||
def add_summary(text):
|
def add_summary(text):
|
||||||
global summary
|
global summary
|
||||||
summary = summary + text
|
summary = summary + text
|
||||||
|
|
||||||
def set_path(path):
|
def set_path(path):
|
||||||
current_path = getenv('PATH')
|
current_path = getenv('PATH')
|
||||||
if current_path.find('C:\\') > -1: # We are on this platform
|
if current_path.find('C:\\') > -1: # We are on this platform
|
||||||
if path == '':
|
if path == '':
|
||||||
path = ";C:\Program Files\Hewlett-Packard\Sanworks\Element Manager for StorageWorks HSV"
|
path = ";C:\Program Files\Hewlett-Packard\Sanworks\Element Manager for StorageWorks HSV"
|
||||||
path = path + ";C:\Program Files (x86)\Compaq\Hpacucli\Bin"
|
path = path + ";C:\Program Files (x86)\Compaq\Hpacucli\Bin"
|
||||||
path = path + ";C:\Program Files\Compaq\Hpacucli\Bin"
|
path = path + ";C:\Program Files\Compaq\Hpacucli\Bin"
|
||||||
else: path = ';' + path
|
else: path = ';' + path
|
||||||
else: # Unix/Linux, etc
|
else: # Unix/Linux, etc
|
||||||
if path == '': path = ":/usr/sbin"
|
if path == '': path = ":/usr/sbin"
|
||||||
else: path = ':' + path
|
else: path = ':' + path
|
||||||
current_path = "%s%s" % (current_path,path)
|
current_path = "%s%s" % (current_path,path)
|
||||||
environ['PATH'] = current_path
|
environ['PATH'] = current_path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_hpacucli(type='controllers', controller=None):
|
def run_hpacucli(run_type='controllers', controller=None):
|
||||||
if type=='controllers':
|
if run_type=='controllers':
|
||||||
command="hpacucli controller all show detail"
|
command="hpacucli controller all show detail"
|
||||||
elif type=='logicaldisks' or type=='physicaldisks':
|
elif run_type in ('logicaldisks','physicaldisks'):
|
||||||
if controller.has_key('Slot'):
|
if 'Slot' not in controller:
|
||||||
identifier = 'slot=%s' % (controller['Slot'] )
|
add_summary( "Controller not found" )
|
||||||
else:
|
end()
|
||||||
add_summary( "Controller not found" )
|
identifier = 'slot=%s' % (controller['Slot'] )
|
||||||
end()
|
if run_type=='logicaldisks':
|
||||||
if type=='logicaldisks':
|
command = "hpacucli controller %s ld all show detail" % (identifier)
|
||||||
command = "hpacucli controller %s ld all show detail" % (identifier)
|
elif run_type=='physicaldisks':
|
||||||
if type=='physicaldisks':
|
command = "hpacucli controller %s pd all show detail" % (identifier)
|
||||||
command = "hpacucli controller %s pd all show detail" % (identifier)
|
debug ( command )
|
||||||
|
if sudo: command = "sudo " + command
|
||||||
#command="hpacucli controller slot=1 ld all show detail"
|
output = runCommand(command)
|
||||||
#command="hpacucli controller slot=1 ld all show detail"
|
# Some basic error checking
|
||||||
debug ( command )
|
error_strings = [ 'Permission denied' ]
|
||||||
if sudo: command = "sudo " + command
|
error_strings.append('Error: You need to have administrator rights to continue.')
|
||||||
output = runCommand(command)
|
for error in error_strings:
|
||||||
# Some basic error checking
|
if output.find( error ) > -1 and output.find("sudo") != 0:
|
||||||
error_strings = [ 'Permission denied' ]
|
command = "sudo " + command
|
||||||
error_strings.append('Error: You need to have administrator rights to continue.')
|
print command
|
||||||
for error in error_strings:
|
output = runCommand(command)
|
||||||
if output.find( error ) > -1 and output.find("sudo") != 0:
|
output = output.split('\n')
|
||||||
command = "sudo " + command
|
objects = []
|
||||||
print command
|
my_object = None
|
||||||
output = runCommand(command)
|
for i in output:
|
||||||
output = output.split('\n')
|
if len(i) == 0:
|
||||||
objects = []
|
continue
|
||||||
object = None
|
if i.strip() == '':
|
||||||
for i in output:
|
continue
|
||||||
if len(i) == 0: continue
|
if i.startswith('Note:'):
|
||||||
if i.strip() == '': continue
|
continue
|
||||||
if i.startswith('Note:'): continue
|
if run_type=='controllers' and i[0] != ' ': # No space on first line
|
||||||
if type=='controllers' and i[0] != ' ': # No space on first line
|
if my_object and not my_object in objects: objects.append(my_object)
|
||||||
if object and not object in objects: objects.append(object)
|
my_object = {}
|
||||||
object = {}
|
my_object['name'] = i
|
||||||
object['name'] = i
|
elif run_type=='logicaldisks' and i.find('Logical Drive:') > 0:
|
||||||
elif type=='logicaldisks' and i.find('Logical Drive:') > 0:
|
if my_object and not my_object in objects: objects.append(my_object)
|
||||||
if object and not object in objects: objects.append(object)
|
my_object = {}
|
||||||
object = {}
|
my_object['name'] = i.strip()
|
||||||
object['name'] = i.strip()
|
elif run_type=='physicaldisks' and i.find('physicaldrive') > 0:
|
||||||
elif type=='physicaldisks' and i.find('physicaldrive') > 0:
|
if my_object and not my_object in objects: objects.append(my_object)
|
||||||
if object and not object in objects: objects.append(object)
|
my_object = {}
|
||||||
object = {}
|
my_object['name'] = i.strip()
|
||||||
object['name'] = i.strip()
|
else:
|
||||||
else:
|
i = i.strip()
|
||||||
i = i.strip()
|
if i.find(':') < 1: continue
|
||||||
if i.find(':') < 1: continue
|
i = i.split(':')
|
||||||
i = i.split(':')
|
if i[0] == '': continue # skip empty lines
|
||||||
if i[0] == '': continue # skip empty lines
|
if len(i) == 1: continue
|
||||||
if len(i) == 1: continue
|
key = i[0].strip()
|
||||||
key = i[0].strip()
|
value = ' '.join( i[1:] ).strip()
|
||||||
value = ' '.join( i[1:] ).strip()
|
my_object[key] = value
|
||||||
object[key] = value
|
if my_object and not my_object in objects: objects.append(my_object)
|
||||||
if object and not object in objects: objects.append(object)
|
return objects
|
||||||
return objects
|
|
||||||
|
|
||||||
controllers = []
|
controllers = []
|
||||||
def check_controllers():
|
def check_controllers():
|
||||||
global controllers
|
global controllers
|
||||||
status = -1
|
status = -1
|
||||||
controllers = run_hpacucli()
|
controllers = run_hpacucli()
|
||||||
if len(controllers) == 0:
|
if len(controllers) == 0:
|
||||||
add_summary("No Disk Controllers Found. Exiting...")
|
add_summary("No Disk Controllers Found. Exiting...")
|
||||||
global nagios_state
|
global nagios_state
|
||||||
nagios_state = unknown
|
nagios_state = unknown
|
||||||
end()
|
end()
|
||||||
add_summary( "Found %s controllers" % ( len(controllers) ) )
|
add_summary( "Found %s controllers" % ( len(controllers) ) )
|
||||||
for i in controllers:
|
for i in controllers:
|
||||||
controller_status = check(i, 'Controller Status', 'OK' )
|
controller_status = check(i, 'Controller Status', 'OK' )
|
||||||
status = max(status, controller_status)
|
status = max(status, controller_status)
|
||||||
|
|
||||||
cache_status = check(i, 'Cache Status' )
|
cache_status = check(i, 'Cache Status' )
|
||||||
status = max(status, cache_status)
|
status = max(status, cache_status)
|
||||||
|
|
||||||
controller_serial = 'n/a'
|
controller_serial = 'n/a'
|
||||||
cache_serial = 'n/a'
|
cache_serial = 'n/a'
|
||||||
if i.has_key('Serial Number'):
|
if i.has_key('Serial Number'):
|
||||||
controller_serial = i['Serial Number']
|
controller_serial = i['Serial Number']
|
||||||
if i.has_key('Cache Serial Number'):
|
if i.has_key('Cache Serial Number'):
|
||||||
cache_serial = i['Cache Serial Number']
|
cache_serial = i['Cache Serial Number']
|
||||||
add_long ( "%s" % (i['name']) )
|
add_long ( "%s" % (i['name']) )
|
||||||
add_long( "- Controller Status: %s (sn: %s)" % ( state[controller_status], controller_serial ) )
|
add_long( "- Controller Status: %s (sn: %s)" % ( state[controller_status], controller_serial ) )
|
||||||
add_long( "- Cache Status: %s (sn: %s)" % ( state[cache_status], cache_serial ) )
|
add_long( "- Cache Status: %s (sn: %s)" % ( state[cache_status], cache_serial ) )
|
||||||
|
|
||||||
if controller_status > ok or cache_status > ok:
|
if controller_status > ok or cache_status > ok:
|
||||||
add_summary( ";%s on %s;" % (state[controller_status], i['name']) )
|
add_summary( ";%s on %s;" % (state[controller_status], i['name']) )
|
||||||
|
|
||||||
add_summary(', ')
|
add_summary(', ')
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
||||||
def check_logicaldisks():
|
def check_logicaldisks():
|
||||||
global controllers
|
global controllers
|
||||||
if len(controllers) < 1:
|
if len(controllers) < 1:
|
||||||
controllers = run_hpacucli()
|
controllers = run_hpacucli()
|
||||||
logicaldisks = []
|
logicaldisks = []
|
||||||
for controller in controllers:
|
for controller in controllers:
|
||||||
for ld in run_hpacucli(type='logicaldisks', controller=controller):
|
for ld in run_hpacucli(run_type='logicaldisks', controller=controller):
|
||||||
logicaldisks.append ( ld )
|
logicaldisks.append ( ld )
|
||||||
status = -1
|
status = -1
|
||||||
add_long("\nChecking logical Disks:" )
|
add_long("\nChecking logical Disks:" )
|
||||||
add_summary( "%s logicaldisks" % ( len(logicaldisks) ) )
|
add_summary( "%s logicaldisks" % ( len(logicaldisks) ) )
|
||||||
for i in logicaldisks:
|
for i in logicaldisks:
|
||||||
ld_status = check(i, 'Status' )
|
ld_status = check(i, 'Status' )
|
||||||
status = max(status, ld_status)
|
status = max(status, ld_status)
|
||||||
|
|
||||||
mount_point = i['Mount Points']
|
mount_point = i['Mount Points']
|
||||||
add_long( "- %s (%s) = %s" % (i['name'], mount_point, state[ld_status]) )
|
add_long( "- %s (%s) = %s" % (i['name'], mount_point, state[ld_status]) )
|
||||||
add_summary(". ")
|
add_summary(". ")
|
||||||
|
|
||||||
def check_physicaldisks():
|
def check_physicaldisks():
|
||||||
global controllers
|
global controllers
|
||||||
disktype='physicaldisks'
|
disktype='physicaldisks'
|
||||||
if len(controllers) < 1:
|
if len(controllers) < 1:
|
||||||
controllers = run_hpacucli()
|
controllers = run_hpacucli()
|
||||||
disks = []
|
disks = []
|
||||||
for controller in controllers:
|
for controller in controllers:
|
||||||
for disk in run_hpacucli(type=disktype, controller=controller):
|
for disk in run_hpacucli(run_type=disktype, controller=controller):
|
||||||
disks.append ( disk )
|
disks.append ( disk )
|
||||||
status = -1
|
status = -1
|
||||||
add_long("\nChecking Physical Disks:" )
|
add_long("\nChecking Physical Disks:" )
|
||||||
add_summary( "%s %s" % ( len(disks), disktype ) )
|
add_summary( "%s %s" % ( len(disks), disktype ) )
|
||||||
for i in disks:
|
for i in disks:
|
||||||
disk_status = check(i, 'Status' )
|
disk_status = check(i, 'Status' )
|
||||||
status = max(status, disk_status)
|
status = max(status, disk_status)
|
||||||
|
|
||||||
size = i['Size']
|
size = i['Size']
|
||||||
firmware = i['Firmware Revision']
|
firmware = i['Firmware Revision']
|
||||||
interface = i['Interface Type']
|
interface = i['Interface Type']
|
||||||
serial = i['Serial Number']
|
serial = i['Serial Number']
|
||||||
model = i['Model']
|
model = i['Model']
|
||||||
add_long( "- %s, %s, %s = %s" % (i['name'], interface, size, state[disk_status]) )
|
add_long( "- %s, %s, %s = %s" % (i['name'], interface, size, state[disk_status]) )
|
||||||
if disk_status > ok:
|
if disk_status > ok:
|
||||||
add_long( "-- Replace drive, firmware=%s, model=%s, serial=%s" % (firmware,model, serial))
|
add_long( "-- Replace drive, firmware=%s, model=%s, serial=%s" % (firmware,model, serial))
|
||||||
if status > ok:
|
if status > ok:
|
||||||
add_summary( "(errors)" )
|
add_summary( "(errors)" )
|
||||||
add_summary(". ")
|
add_summary(". ")
|
||||||
|
|
||||||
|
|
||||||
def check(object, field, valid_states = ['OK']):
|
def check(my_object, field, valid_states = None):
|
||||||
state = -1
|
if valid_states is None:
|
||||||
global nagios_status
|
valid_states = ['OK']
|
||||||
if object.has_key(field):
|
state = -1
|
||||||
if object[field] in valid_states:
|
global nagios_status
|
||||||
state = ok
|
if my_object.has_key(field):
|
||||||
else:
|
if my_object[field] in valid_states:
|
||||||
state = warning
|
state = ok
|
||||||
nagios_status = max(nagios_status, state)
|
else:
|
||||||
return state
|
state = warning
|
||||||
|
nagios_status = max(nagios_status, state)
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
arguments = argv[1:]
|
arguments = argv[1:]
|
||||||
while len(arguments) > 0:
|
while len(arguments) > 0:
|
||||||
arg = arguments.pop(0)
|
arg = arguments.pop(0)
|
||||||
if arg == '--help':
|
if arg == '--help':
|
||||||
print_help()
|
print_help()
|
||||||
exit(ok)
|
exit(ok)
|
||||||
elif arg == '--path':
|
elif arg == '--path':
|
||||||
path = arguments.pop(0)
|
path = arguments.pop(0)
|
||||||
set_path(path)
|
set_path(path)
|
||||||
elif arg == '--debug':
|
elif arg == '--debug':
|
||||||
global debugging
|
global debugging
|
||||||
debugging = True
|
debugging = True
|
||||||
elif arg == '--sudo':
|
elif arg == '--sudo':
|
||||||
global sudo
|
global sudo
|
||||||
sudo = True
|
sudo = True
|
||||||
else:
|
else:
|
||||||
print_help()
|
print_help()
|
||||||
exit(unknown)
|
exit(unknown)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parse_arguments()
|
parse_arguments()
|
||||||
set_path('')
|
set_path('')
|
||||||
check_controllers()
|
check_controllers()
|
||||||
check_logicaldisks()
|
check_logicaldisks()
|
||||||
check_physicaldisks()
|
check_physicaldisks()
|
||||||
end()
|
end()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user