1
0
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:
Pall Sigurdsson 2013-05-27 16:42:27 +00:00
parent 3cf6cb7f2d
commit f06667b55d

View File

@ -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,8 +82,8 @@ 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):
""" Runs command from the shell prompt. Exit Nagios style if unsuccessful"""
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,) proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
stdout, stderr = proc.communicate('through stdin to stdout') stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0: if proc.returncode > 0:
@ -140,22 +140,18 @@ def set_path(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'] )
else:
add_summary( "Controller not found" ) add_summary( "Controller not found" )
end() end()
if type=='logicaldisks': identifier = 'slot=%s' % (controller['Slot'] )
if run_type=='logicaldisks':
command = "hpacucli controller %s ld all show detail" % (identifier) command = "hpacucli controller %s ld all show detail" % (identifier)
if type=='physicaldisks': elif run_type=='physicaldisks':
command = "hpacucli controller %s pd all show detail" % (identifier) command = "hpacucli controller %s pd all show detail" % (identifier)
#command="hpacucli controller slot=1 ld all show detail"
#command="hpacucli controller slot=1 ld all show detail"
debug ( command ) debug ( command )
if sudo: command = "sudo " + command if sudo: command = "sudo " + command
output = runCommand(command) output = runCommand(command)
@ -169,23 +165,26 @@ def run_hpacucli(type='controllers', controller=None):
output = runCommand(command) output = runCommand(command)
output = output.split('\n') output = output.split('\n')
objects = [] objects = []
object = None my_object = None
for i in output: for i in output:
if len(i) == 0: continue if len(i) == 0:
if i.strip() == '': continue continue
if i.startswith('Note:'): continue if i.strip() == '':
if type=='controllers' and i[0] != ' ': # No space on first line continue
if object and not object in objects: objects.append(object) if i.startswith('Note:'):
object = {} continue
object['name'] = i if run_type=='controllers' and i[0] != ' ': # No space on first line
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
object['name'] = i.strip() elif run_type=='logicaldisks' and i.find('Logical Drive:') > 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() elif run_type=='physicaldisks' and i.find('physicaldrive') > 0:
if my_object and not my_object in objects: objects.append(my_object)
my_object = {}
my_object['name'] = i.strip()
else: else:
i = i.strip() i = i.strip()
if i.find(':') < 1: continue if i.find(':') < 1: continue
@ -194,8 +193,8 @@ def run_hpacucli(type='controllers', controller=None):
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()
object[key] = value my_object[key] = value
if object and not object in objects: objects.append(object) if my_object and not my_object in objects: objects.append(my_object)
return objects return objects
controllers = [] controllers = []
@ -239,7 +238,7 @@ def check_logicaldisks():
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:" )
@ -259,7 +258,7 @@ def check_physicaldisks():
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:" )
@ -281,11 +280,13 @@ def check_physicaldisks():
add_summary(". ") add_summary(". ")
def check(object, field, valid_states = ['OK']): def check(my_object, field, valid_states = None):
if valid_states is None:
valid_states = ['OK']
state = -1 state = -1
global nagios_status global nagios_status
if object.has_key(field): if my_object.has_key(field):
if object[field] in valid_states: if my_object[field] in valid_states:
state = ok state = ok
else: else:
state = warning state = warning