1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-25 03:43: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
#
# 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
debugging = False
@ -82,8 +82,8 @@ def debug( debugtext ):
print debugtext
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
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,)
stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0:
@ -140,22 +140,18 @@ def set_path(path):
def run_hpacucli(type='controllers', controller=None):
if type=='controllers':
def run_hpacucli(run_type='controllers', controller=None):
if run_type=='controllers':
command="hpacucli controller all show detail"
elif type=='logicaldisks' or type=='physicaldisks':
if controller.has_key('Slot'):
identifier = 'slot=%s' % (controller['Slot'] )
else:
elif run_type in ('logicaldisks','physicaldisks'):
if 'Slot' not in controller:
add_summary( "Controller not found" )
end()
if type=='logicaldisks':
identifier = 'slot=%s' % (controller['Slot'] )
if run_type=='logicaldisks':
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 slot=1 ld all show detail"
#command="hpacucli controller slot=1 ld all show detail"
debug ( command )
if sudo: command = "sudo " + command
output = runCommand(command)
@ -169,23 +165,26 @@ def run_hpacucli(type='controllers', controller=None):
output = runCommand(command)
output = output.split('\n')
objects = []
object = None
my_object = None
for i in output:
if len(i) == 0: continue
if i.strip() == '': continue
if i.startswith('Note:'): continue
if type=='controllers' and i[0] != ' ': # No space on first line
if object and not object in objects: objects.append(object)
object = {}
object['name'] = i
elif type=='logicaldisks' and i.find('Logical Drive:') > 0:
if object and not object in objects: objects.append(object)
object = {}
object['name'] = i.strip()
elif type=='physicaldisks' and i.find('physicaldrive') > 0:
if object and not object in objects: objects.append(object)
object = {}
object['name'] = i.strip()
if len(i) == 0:
continue
if i.strip() == '':
continue
if i.startswith('Note:'):
continue
if run_type=='controllers' and i[0] != ' ': # No space on first line
if my_object and not my_object in objects: objects.append(my_object)
my_object = {}
my_object['name'] = i
elif run_type=='logicaldisks' and i.find('Logical Drive:') > 0:
if my_object and not my_object in objects: objects.append(my_object)
my_object = {}
my_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:
i = i.strip()
if i.find(':') < 1: continue
@ -194,8 +193,8 @@ def run_hpacucli(type='controllers', controller=None):
if len(i) == 1: continue
key = i[0].strip()
value = ' '.join( i[1:] ).strip()
object[key] = value
if object and not object in objects: objects.append(object)
my_object[key] = value
if my_object and not my_object in objects: objects.append(my_object)
return objects
controllers = []
@ -239,7 +238,7 @@ def check_logicaldisks():
controllers = run_hpacucli()
logicaldisks = []
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 )
status = -1
add_long("\nChecking logical Disks:" )
@ -259,7 +258,7 @@ def check_physicaldisks():
controllers = run_hpacucli()
disks = []
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 )
status = -1
add_long("\nChecking Physical Disks:" )
@ -281,11 +280,13 @@ def check_physicaldisks():
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
global nagios_status
if object.has_key(field):
if object[field] in valid_states:
if my_object.has_key(field):
if my_object[field] in valid_states:
state = ok
else:
state = warning