1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-10 04:23:44 +01:00
nagios-plugins/check_eva/trunk/check_eva.py

694 lines
23 KiB
Python
Raw Normal View History

2010-09-01 17:53:28 +02:00
#!/usr/bin/python
2010-09-01 22:55:07 +02:00
#
# Copyright 2010, Pall Sigurdsson <palli@opensource.is>
#
# check_eva.py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# check_eva.py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# About this script
#
# This script will check the status of all EVA arrays via the sssu binary.
# You will need the sssu binary in path (/usr/bin/sssu is a good place)
# If you do not have sssu, check your commandview CD, it should have both
# binaries for Windows and Linux
# Some Defaults
show_perfdata = True
show_longserviceoutput = True
debugging = False
2010-09-01 17:53:28 +02:00
# check_eva defaults
2010-09-04 03:39:24 +02:00
hostname="localhost"
2010-09-01 17:53:28 +02:00
username="eva"
2010-09-04 03:39:24 +02:00
password="eva1234"
2010-09-01 20:45:05 +02:00
mode="check_systems"
path=''
nagios_server = "94.142.154.10"
nagios_port = 80
nagios_myhostname = None
do_phone_home = False
2010-09-08 18:11:35 +02:00
escape_newlines = False
check_system = None # By default check all systems
2010-10-06 16:56:25 +02:00
proxyserver = None
2010-09-01 17:53:28 +02:00
2010-10-25 20:48:06 +02:00
server_side_troubleshooting = False # set to true, if you do not have sssu binary handy
2010-09-01 17:53:28 +02:00
# No real need to change anything below here
version="1.0"
ok=0
warning=1
critical=2
unknown=3
not_present = -1
2010-09-01 20:45:05 +02:00
2010-09-01 17:53:28 +02:00
state = {}
state[not_present] = "Not Present"
state[ok] = "OK"
state[warning] = "Warning"
state[critical] = "Critical"
state[unknown] = "Unknown"
longserviceoutput="\n"
2010-09-01 22:35:47 +02:00
perfdata=""
2010-09-01 17:53:28 +02:00
valid_modes = ( "check_systems", "check_controllers", "check_diskgroups","check_disks", "check_diskshelfs", "check_diskshelves")
2010-09-01 17:53:28 +02:00
from sys import exit
from sys import argv
2010-10-06 11:51:47 +02:00
from os import getenv,putenv,environ
2010-09-01 17:53:28 +02:00
import subprocess
2010-10-06 16:56:25 +02:00
import xmlrpclib,httplib
2010-09-08 18:07:48 +02:00
import socket
socket.setdefaulttimeout(5)
2010-09-01 17:53:28 +02:00
def print_help():
print "check_eva version %s" % version
2010-09-01 22:55:07 +02:00
print "This plugin checks HP EVA Array with the sssu command"
2010-09-01 17:53:28 +02:00
print ""
print "Usage: %s [OPTIONS]" % argv[0]
print "OPTIONS:"
print " [--host <host>]"
print " [--username <user>]"
print " [--password <password]"
2010-09-01 22:55:07 +02:00
print " [--path </path/to/sssu>]"
2010-09-01 17:53:28 +02:00
print " [--mode <mode>] "
print " [--test]"
2010-09-01 21:14:28 +02:00
print " [--debug]"
2010-09-01 17:53:28 +02:00
print " [--help]"
print ""
print " Valid modes are: %s" % ', '.join(valid_modes)
2010-09-01 22:55:07 +02:00
print ""
print "Example: %s --host commandview.example.net --username eva --password myPassword --mode check_systems" % (argv[0])
2010-09-01 17:53:28 +02:00
def error(errortext):
print "* Error: %s" % errortext
print_help()
print "* Error: %s" % errortext
exit(unknown)
2010-09-01 20:45:05 +02:00
def debug( debugtext ):
2010-09-01 21:14:28 +02:00
global debugging
if debugging:
2010-09-01 20:45:05 +02:00
print debugtext
2010-09-01 17:53:28 +02:00
# parse arguments
arguments=argv[1:]
while len(arguments) > 0:
arg=arguments.pop(0)
if arg == 'invalid':
pass
elif arg == '-H' or arg == '--host':
hostname=arguments.pop(0)
elif arg == '-U' or arg == '--username':
username=arguments.pop(0)
elif arg == '-P' or arg == '--password':
password = arguments.pop(0)
elif arg == '-T' or arg == '--test':
testmode=1
2010-09-01 20:45:05 +02:00
elif arg == '--path':
path = arguments.pop(0) + '/'
2010-09-01 17:53:28 +02:00
elif arg == '-M' or arg == '--mode':
mode=arguments.pop(0)
if mode not in valid_modes:
error("Invalid --mode %s" % arg)
2010-09-01 21:14:28 +02:00
elif arg == '-d' or arg == '--debug':
debugging=True
elif arg == '--longserviceoutput':
show_longserviceoutput = True
elif arg == '--no-longserviceoutput':
show_longserviceoutput = False
elif arg == '--perfdata':
show_perfdata = True
elif arg == '--no-perfdata':
show_perfdata = False
2010-09-08 18:07:48 +02:00
elif arg == '--nagios_myhostname':
nagios_myhostname = arguments.pop(0)
elif arg == '--nagios_server':
2010-09-08 15:57:55 +02:00
nagios_server = arguments.pop(0)
2010-09-09 13:31:13 +02:00
elif arg == '--nagios_port':
2010-09-08 15:57:55 +02:00
nagios_port = arguments.pop(0)
elif arg == '--system':
check_system = arguments.pop(0)
elif arg == '--phone-home':
do_phone_home = True
2010-10-06 16:56:25 +02:00
elif arg == '--proxy':
proxyserver = arguments.pop(0)
2010-09-08 18:11:35 +02:00
elif arg == '--escape-newlines':
escape_newlines = True
elif arg == '-h' or arg == '--help':
2010-09-08 18:07:48 +02:00
print_help()
exit(ok)
2010-09-01 17:53:28 +02:00
else:
error( "Invalid argument %s"% arg)
subitems = {}
subitems['fan'] = 'fans'
subitems['source'] = 'powersources'
subitems['hostport'] = 'hostports'
subitems['module'] = 'modules'
subitems['sensor'] = 'sensors'
2010-09-01 20:45:05 +02:00
subitems['powersupply'] = 'powersupplies'
2010-09-01 22:35:47 +02:00
subitems['bus'] = 'communicationbuses'
subitems['port'] = 'fibrechannelports'
2010-09-01 17:53:28 +02:00
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
def runCommand(command):
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,)
stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0:
2010-09-02 19:36:39 +02:00
print "Error %s: %s\n command was: '%s'" % (proc.returncode,stderr.strip(),command)
2010-10-06 11:51:47 +02:00
if proc.returncode == 127 or proc.returncode == 1: # File not found, lets print path
2010-09-02 20:12:32 +02:00
path=getenv("PATH")
2010-09-02 20:07:17 +02:00
print "Current Path: %s" % (path)
2010-09-01 17:53:28 +02:00
exit(unknown)
else:
return stdout
'''Runs the sssu command. This one is responsible for error checking from sssu'''
def run_sssu(system=None, command="ls system full"):
commands = []
continue_on_error="set option on_error=continue"
login="select manager %s USERNAME=%s PASSWORD=%s"%(hostname,username,password)
commands.append(continue_on_error)
commands.append(login)
if system != None:
commands.append('select SYSTEM "%s"' % system)
2010-09-01 17:53:28 +02:00
commands.append(command)
commandstring = "sssu "
for i in commands: commandstring = commandstring + "'%s' " % i
2010-10-25 20:48:06 +02:00
global server_side_troubleshooting
if server_side_troubleshooting == True:
commandstring = 'cat "debug/%s"' % command
2010-09-01 17:53:28 +02:00
#print mystring
2010-09-01 20:45:05 +02:00
#if command == "ls system full":
# output = runCommand("cat sssu.out")
#elif command == "ls disk_groups full":
# output = runCommand("cat ls_disk*")
#elif command == "ls controller full":
# output = runCommand("cat ls_controller")
#else:
# print "What command is this?", command
# exit(unknown)
output = runCommand(commandstring)
debug( commandstring )
2010-09-01 17:53:28 +02:00
output = output.split('\n')
# Lets process the top few results from the sssu command. Make sure the results make sense
error = 0
2010-09-02 20:07:17 +02:00
if output.pop(0).strip() != '': error = 1
if output.pop(0).strip() != '': error = 1
if output.pop(0).strip() != 'SSSU for HP StorageWorks Command View EVA': error = 1
if output.pop(0).strip().find('Version:') != 0: error=1
if output.pop(0).strip().find('Build:') != 0: error=1
if output.pop(0).strip().find('NoSystemSelected> ') != 0: error=1
2010-09-04 03:39:24 +02:00
#if output.pop(0).strip() != '': error = 1
#if output.pop(0).strip().find('NoSystemSelected> ') != 0: error=1
#if output.pop(0).strip() != '': error = 1
2010-09-01 17:53:28 +02:00
buffer = ""
for i in output:
buffer = buffer + i + "\n"
2010-09-04 03:39:24 +02:00
if i.find('Error') > -1:
print "This is the command i was trying to execute: %s" % i
2010-09-01 17:53:28 +02:00
error = 1
if i.find('information:') > 0: break
if error > 0:
print "Error running the sssu command"
print commandstring
print buffer
exit(unknown)
objects = []
object = None
parent_object = None
for line in output:
if len(line) == 0:
continue
line = line.strip()
tmp = line.split()
if len(tmp) == 0:
if object:
if not object['master'] in objects: objects.append( object['master'] )
object = None
continue
key = tmp[0].strip()
if object and not object['master'] in objects: objects.append( object['master'] )
if key == 'object':
object = {}
object['master'] = object
if key == 'controllertemperaturestatus':
object = object['master']
2010-09-01 20:45:05 +02:00
if key == 'iomodules':
key = 'modules'
2010-09-01 21:14:28 +02:00
#if key in subitems.values():
# object['master'][key] = []
2010-09-01 17:53:28 +02:00
if key in subitems.keys():
mastergroup = subitems[key]
master = object['master']
object = {}
object['object_type'] = key
object['master'] = master
2010-09-01 21:14:28 +02:00
if not object['master'].has_key(mastergroup):
object['master'][mastergroup] = []
2010-09-01 17:53:28 +02:00
object['master'][mastergroup].append(object)
if line.find('.:') > 0:
# We work on first come, first serve basis, so if
# we accidentally see same key again, we will ignore
if not object.has_key(key):
value = ' '.join( tmp[2:] ).strip()
object[key] = value
# Check if we were instructed to check only one eva system
global check_system
if command == "ls system full" and check_system != None:
tmp_objects = []
for i in objects:
if i['objectname'] == check_system:
tmp_objects.append( i )
objects = tmp_objects
2010-09-01 17:53:28 +02:00
return objects
def end(summary,perfdata,longserviceoutput,nagios_state):
global show_longserviceoutput
global show_perfdata
2010-09-08 15:57:55 +02:00
global nagios_server
global do_phone_home
2010-09-08 15:57:55 +02:00
global nagios_port
2010-09-08 18:07:48 +02:00
global nagios_myhostname
global hostname
global mode
2010-09-08 18:11:35 +02:00
global escape_newlines
global check_system
2010-09-08 15:57:55 +02:00
message = "%s - %s" % ( state[nagios_state], summary)
if show_perfdata:
message = "%s | %s" % ( message, perfdata)
if show_longserviceoutput:
2010-09-08 18:07:48 +02:00
message = "%s\n%s" % ( message, longserviceoutput.strip())
2010-09-08 18:24:34 +02:00
if escape_newlines == True:
lines = message.split('\n')
message = '\\n'.join(lines)
debug( "do_phone_home = %s" %(do_phone_home) )
if do_phone_home == True:
2010-09-08 18:07:48 +02:00
try:
2010-10-20 16:25:23 +02:00
if nagios_myhostname is None:
if environ.has_key( 'HOSTNAME' ):
nagios_myhostname = environ['HOSTNAME']
elif environ.has_key( 'COMPUTERNAME' ):
nagios_myhostname = environ['COMPUTERNAME']
else:
nagios_myhostname = hostname
try: phone_home(nagios_server,nagios_port, status=nagios_state, message=message, hostname=nagios_myhostname, servicename=mode,system=check_system)
except:pass
2010-09-08 18:07:48 +02:00
except:
2010-10-06 16:56:25 +02:00
raise
2010-09-08 15:57:55 +02:00
print message
2010-09-01 17:53:28 +02:00
exit(nagios_state)
2010-10-06 16:56:25 +02:00
class ProxiedTransport(xmlrpclib.Transport):
def set_proxy(self, proxy):
self.proxy = proxy
def make_connection(self, host):
self.realhost = host
h = httplib.HTTP(self.proxy)
return h
def send_request(self, connection, handler, request_body):
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
def send_host(self, connection, host):
connection.putheader('Host', self.realhost)
2010-09-01 17:53:28 +02:00
2010-09-08 16:37:32 +02:00
''' phone_home: Sends results to remote nagios server via python xml-rpc '''
def phone_home(nagios_server,nagios_port, status, message, hostname=None, servicename=None,system=None):
debug("phoning home: %s" % (servicename) )
2010-10-20 16:25:23 +02:00
if system is not None:
servicename = str(servicename) + str(system)
2010-09-08 18:07:48 +02:00
uri = "http://%s:%s" % (nagios_server,nagios_port)
2010-10-06 16:56:25 +02:00
global proxyserver
if proxyserver != None:
p = ProxiedTransport()
p.set_proxy(proxyserver)
s = xmlrpclib.Server( uri, transport=p )
else:
s = xmlrpclib.ServerProxy( uri )
2010-09-08 18:07:48 +02:00
s.nagiosupdate(hostname, servicename, status, message)
return 0
2010-09-08 16:37:32 +02:00
2010-09-01 20:45:05 +02:00
def check_systems():
2010-09-01 17:53:28 +02:00
summary=""
perfdata=""
#longserviceoutput="\n"
nagios_state = ok
objects = run_sssu()
for i in objects:
name = i['objectname']
operationalstate = i['operationalstate']
# Lets see if this array is working
if operationalstate != 'good':
nagios_state = max(nagios_state, warning)
# Lets add to the summary
summary = summary + " %s=%s " %(name, operationalstate)
# Collect the performance data
interesting_perfdata = 'totalstoragespace|usedstoragespace|availablestoragespace'
perfdata = perfdata + get_perfdata(i,interesting_perfdata.split('|'), identifier="%s_"% name)
# Collect extra info for longserviceoutput
long("%s = %s (%s)\n" % ( i['objectname'], i['operationalstate'], i['operationalstatedetail']) )
interesting_fields = 'licensestate|systemtype|firmwareversion|nscfwversion|totalstoragespace|usedstoragespace|availablestoragespace'
for x in interesting_fields.split('|'):
2010-09-01 20:45:05 +02:00
long( "- %s = %s \n" %(x, i[x]) )
2010-09-01 17:53:28 +02:00
long("\n")
end(summary,perfdata,longserviceoutput,nagios_state)
def get_perfdata(object, interesting_fields, identifier=""):
perfdata = ""
for i in interesting_fields:
if i == '': continue
perfdata = perfdata + "'%s%s'=%s " % (identifier, i, object[i])
return perfdata
2010-09-01 22:35:47 +02:00
def add_perfdata(text):
global perfdata
text = text.strip()
perfdata = perfdata + " %s " % (text)
2010-09-01 17:53:28 +02:00
def long(text):
global longserviceoutput
longserviceoutput = longserviceoutput + text
def get_longserviceoutput(object, interesting_fields):
longserviceoutput = ""
for i in interesting_fields:
longserviceoutput = longserviceoutput + "%s = %s \n" %(i, object[i])
return longserviceoutput
2010-09-01 22:35:47 +02:00
def check_operationalstate(object, print_failed_objects=False,namefield='objectname',detailfield='operationalstatedetail',statefield='operationalstate',valid_states=['good']):
if not object.has_key(detailfield): detailfield = statefield
if not object.has_key(statefield):
if print_failed_objects:
long("- Warning, %s does not have any '%s'" % ( object[namefield], statefield ) )
return warning
if object[statefield] not in valid_states:
2010-09-01 20:45:05 +02:00
if print_failed_objects:
2010-10-25 17:15:43 +02:00
long("- Warning, %s=%s (%s)\n" % ( object[namefield], object['operationalstate'], object[detailfield] ))
2010-09-01 17:53:28 +02:00
return warning
2010-09-01 20:45:05 +02:00
debug( "OK, %s=%s (%s)\n" % ( object[namefield], object['operationalstate'], object[detailfield] ) )
2010-09-01 17:53:28 +02:00
return ok
2010-09-01 20:45:05 +02:00
def check_generic(command="ls disk full",namefield="objectname", perfdata_fields=[], longserviceoutputfields=[], detailedsummary=False):
summary=""
2010-09-01 22:35:47 +02:00
global perfdata
2010-09-01 20:45:05 +02:00
nagios_state = ok
systems = run_sssu()
objects = []
2010-09-01 22:35:47 +02:00
if command == 'ls system full':
objects = systems
for i in systems: i['systemname'] = '' #i['objectname']
else:
for i in systems:
result = run_sssu(system=i['objectname'], command=command)
for x in result:
x['systemname'] = i['objectname']
objects.append( x )
2010-09-01 20:45:05 +02:00
summary = "%s objects found " % len(objects)
for i in objects:
systemname = i['systemname']
2010-10-25 19:47:39 +02:00
# Some versions of commandview use "objectname" instead of namefield
if i.has_key( namefield ):
objectname = i[namefield]
else:
objectname = i['objectname']
# Some versions of CV also return garbage objects, luckily it is easy to find these
if i.has_key('objecttype') and i['objecttype'] == 'typenotset':
long("Object %s was skipped because objecttype == typenotset\n" % objectname )
continue
2010-09-01 20:45:05 +02:00
# Lets see if this object is working
nagios_state = max( check_operationalstate(i), nagios_state )
# Lets add to the summary
if i['operationalstate'] != 'good' or detailedsummary == True:
summary = summary + " %s/%s=%s " %(systemname,objectname, i['operationalstate'])
# Lets get some perfdata
identifier = "%s/%s_" % (systemname,objectname)
2010-09-01 22:35:47 +02:00
i['identifier'] = identifier
for field in perfdata_fields:
if field == '': continue
add_perfdata( "'%s%s'=%s " % (identifier, field, i[field]) )
# Disk group gets a special perfdata treatment
2010-09-01 20:45:05 +02:00
if command == "ls disk_group full":
2010-09-01 21:14:28 +02:00
totalstoragespacegb= float( i['totalstoragespacegb'] )
usedstoragespacegb= float ( i['usedstoragespacegb'] )
occupancyalarmlvel = float( i['occupancyalarmlevel'] )
warninggb= totalstoragespacegb * occupancyalarmlvel / 100
2010-09-01 22:35:47 +02:00
add_perfdata( " '%sdiskusage'=%s;%s;%s "% (identifier, usedstoragespacegb,warninggb,totalstoragespacegb) )
2010-09-01 20:45:05 +02:00
# Long Serviceoutput
2010-09-01 22:35:47 +02:00
# There are usually to many disks for nagios to display. Skip.
if command != "ls disk full":
2010-09-01 20:45:05 +02:00
long( "\n%s/%s = %s (%s)\n"%(systemname,objectname,i['operationalstate'], i['operationalstatedetail']) )
2010-09-01 22:35:47 +02:00
# If diskgroup has a problem because it is over allocated. Lets inform about that
2010-09-01 20:45:05 +02:00
if command == "ls disk_group full" and usedstoragespacegb > warninggb:
2010-09-01 21:14:28 +02:00
long("- %s - diskgroup usage is over %s%% threshold !\n" % (state[warning], occupancyalarmlvel) )
2010-09-01 22:35:47 +02:00
# If a disk has a problem, lets display some extra info on it
2010-09-01 20:45:05 +02:00
elif command == "ls disk full" and i['operationalstate'] != 'good':
long( "Warning - %s=%s (%s)\n" % (i['diskname'], i['operationalstate'], i['operationalstatedetail'] ))
fields="modelnumber firmwareversion serialnumber failurepredicted diskdrivetype".split()
for field in fields:
long( "- %s = %s\n" % (field, i[field]) )
2010-09-01 22:35:47 +02:00
nagios_state = max(nagios_state, check_multiple_objects(i, 'sensors'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'fans'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'powersupplies'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'communicationbuses'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'fibrechannelports'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'modules'))
2010-09-01 20:45:05 +02:00
for x in longserviceoutputfields:
2010-10-25 19:07:06 +02:00
if i.has_key( x ):
long( "- %s = %s\n" % (x, i[x]))
2010-09-01 20:45:05 +02:00
end(summary,perfdata,longserviceoutput,nagios_state)
2010-09-01 22:35:47 +02:00
def check_multiple_objects(object, name):
item_status = not_present
if object.has_key(name):
item_status = not_present
valid_states=['good']
namefield="name"
detailfield = 'operationalstatedetail'
if name == 'fans' or name == 'sensors':
valid_states = ['good','notavailable','unsupported','notinstalled']
elif name == 'fibrechannelports':
valid_states.append( 'notinstalled' )
2010-09-01 22:35:47 +02:00
num_items = len(object[name])
for item in object[name]:
stat = check_operationalstate( item,print_failed_objects=True, namefield=namefield, valid_states=valid_states,detailfield=detailfield)
item_status = max( stat, item_status )
long('- %s on %s (%s detected)\n'% (state[item_status], name, num_items) )
add_perfdata( " '%s%s'=%s" % (object['identifier'],name, num_items) )
return item_status
2010-09-01 20:45:05 +02:00
2010-09-01 17:53:28 +02:00
def check_controllers():
summary=""
perfdata=""
#longserviceoutput="\n"
nagios_state = ok
systems = run_sssu()
controllers =[]
for i in systems:
2010-09-01 20:45:05 +02:00
result = run_sssu(system=i['objectname'], command="ls controller full")
2010-09-01 17:53:28 +02:00
for controller in result:
controller['systemname'] = i['objectname']
controllers.append( controller )
2010-10-25 21:11:22 +02:00
summary = "%s objects found " % len(controllers)
2010-09-01 17:53:28 +02:00
for i in controllers:
systemname = i['systemname']
if i.has_key('controllername'):
controllername = i['controllername']
else:
controllername = i['objectname']
2010-09-01 17:53:28 +02:00
# Lets see if this controller is working
nagios_state = max( check_operationalstate(i), nagios_state )
# Lets add to the summary
if not i.has_key('operationalstate'):
2010-10-25 21:11:22 +02:00
summary = summary + " %s does not have any operationalstate " % controllername
nagios_state = max( unknown, nagios_state )
continue
elif i['operationalstate'] != 'good':
2010-10-12 17:37:46 +02:00
summary = summary + " %s/%s=%s " %(systemname,controllername, i['operationalstate'])
2010-09-01 17:53:28 +02:00
# Lets get some perfdata
interesting_fields = "controllermainmemory"
2010-09-01 20:45:05 +02:00
identifier = "%s/%s_" % (systemname,controllername)
2010-09-01 17:53:28 +02:00
perfdata = perfdata + get_perfdata(i, interesting_fields.split('|'), identifier=identifier)
# Long Serviceoutput
interesting_fields = "operationalstate|operationalstatedetail|firmwareversion|serialnumber"
#longserviceoutput = longserviceoutput + get_longserviceoutput(i, interesting_fields.split('|') )
#longserviceoutput = longserviceoutput + "\n%s/%s\n"%(systemname,controllername)
long( "\n%s/%s = %s (%s)\n"%(systemname,controllername,i['operationalstate'], i['operationalstatedetail']) )
2010-09-02 19:36:39 +02:00
long( "- firmwareversion = %s \n" %(i['firmwareversion']))
long( "- serialnumber = %s \n" %(i['serialnumber']))
2010-09-01 17:53:28 +02:00
controllertemperaturestatus = not_present
cache_state = not_present
fanstate = not_present
hostportstate = not_present
sensorstate = ok
source_state = not_present
module_state = not_present
# Check the cache status
if i['cachecondition'] == 'good':
cache_state = ok
else:
cache_state = warning
# Check Temperature
2010-09-01 20:45:05 +02:00
if i.has_key("controllertemperaturestatus"):
if i['controllertemperaturestatus'] == 'normal':
controllertemperaturestatus = ok
else:
controllertemperaturestatus = warning
2010-09-01 17:53:28 +02:00
# Process the subsensors
for hostport in i['hostports']:
#long(" %s = %s\n" % (hostport['portname'], hostport['operationalstate']))
hostportstate = max(hostportstate,ok)
if hostport['operationalstate'] != 'good':
hostportstate = max(warning,hostport_state)
long("Hostport %s state = %s\n" % hostport['portname'], hostport['operationalstate'])
2010-09-01 21:14:28 +02:00
if i.has_key('fans'):
for fan in i['fans']:
fanstate = max(fanstate,ok)
#long(" %s = %s\n" % (fan['fanname'], fan['status']))
if fan.has_key('status'): status = fan['status']
elif fan.has_key('installstatus'): status = fan['installstatus']
if status != 'normal' and status != 'yes':
fanstate = max(warning,fanstate)
long("Fan %s status = %s\n" % (fan['fanname'],status))
if i.has_key('powersources'):
for source in i['powersources']:
source_state = max(source_state,ok)
if not source.has_key('status'): continue
if source['state'] != 'good':
source_state = max(warning,source_state)
long("Powersource %s status = %s\n" % (source['type'],source['state']))
if i.has_key('modules'):
for module in i['modules']:
module_state = max(module_state,ok)
if module['operationalstate'] not in ('good','not_present'):
module_state = max(warning,module_state)
long("Battery Module %s status = %s\n" % (module['name'],module['operationalstate']))
2010-09-01 17:53:28 +02:00
for i in (fanstate,hostportstate,sensorstate,source_state,module_state,cache_state,controllertemperaturestatus):
nagios_state = max(nagios_state, i)
2010-09-01 20:45:05 +02:00
long("- %s on fans\n"%( state[fanstate] ) )
long("- %s on cachememory\n"%( state[cache_state] ) )
long("- %s on temperature\n"%( state[controllertemperaturestatus] ) )
long("- %s on hostports\n"%( state[hostportstate] ) )
long("- %s on sensors\n"%( state[sensorstate] ) )
long("- %s on powersupplies\n"%( state[source_state] ) )
long("- %s on batterymodules\n"%( state[module_state] ) )
2010-09-01 17:53:28 +02:00
long('\n')
end(summary,perfdata,longserviceoutput,nagios_state)
2010-09-02 20:07:17 +02:00
def set_path():
global path
current_path = getenv('PATH')
2010-09-02 20:12:32 +02:00
if path == '':
2010-09-02 20:14:23 +02:00
if current_path.find('C:\\') > -1: # We are on this platform
2010-10-06 11:51:47 +02:00
path = ";C:\\Program Files\\Hewlett-Packard\\Sanworks\\Element Manager for StorageWorks HSV"
2010-09-02 20:12:32 +02:00
else:
2010-10-06 11:51:47 +02:00
path = ":/usr/local/bin"
current_path = "%s%s" % (current_path,path)
environ['PATH'] = current_path
2010-09-02 20:07:17 +02:00
set_path()
2010-09-01 20:45:05 +02:00
if mode == 'check_systems':
2010-09-01 22:35:47 +02:00
perfdata_fields = 'totalstoragespace usedstoragespace availablestoragespace'.split()
longserviceoutputfields = 'licensestate systemtype firmwareversion nscfwversion totalstoragespace usedstoragespace availablestoragespace'.split()
command = "ls system full"
namefield="objectname"
check_generic(command=command,namefield=namefield,longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields)
#check_systems
2010-09-01 17:53:28 +02:00
elif mode == 'check_controllers':
check_controllers()
elif mode == 'check_diskgroups':
2010-09-01 20:45:05 +02:00
command = "ls disk_group full"
namefield='diskgroupname'
longserviceoutputfields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel".split()
2010-09-01 22:35:47 +02:00
perfdata_fields="totaldisks".split()
2010-09-01 20:45:05 +02:00
check_generic(command=command,namefield=namefield,longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields)
elif mode == 'check_disks':
check_generic(command="ls disk full",namefield="objectname")
elif mode == 'check_diskshelfs' or mode == 'check_diskshelves':
2010-09-01 20:45:05 +02:00
check_generic(command="ls diskshelf full",namefield="diskshelfname",longserviceoutputfields=[], perfdata_fields=[])
2010-09-01 17:53:28 +02:00
else:
print "* Error: Mode %s not found" % mode
print_help()
print "* Error: Mode %s not found" % mode
exit(unknown)