1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-14 14:33:46 +01:00
nagios-plugins/check_eva/check_eva.py

768 lines
28 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
2013-09-02 17:14:07 +02:00
#
2010-09-01 22:55:07 +02:00
# 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
2013-09-02 17:14:07 +02:00
hostname = "localhost"
username = "eva"
password = "eva1234"
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
2013-09-02 17:14:07 +02:00
check_system = None # By default check all systems
2010-10-06 16:56:25 +02:00
proxyserver = None
timeout = 0 # 0 means no timeout
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
# set to true, if you do not have sssu binary handy
server_side_troubleshooting = False
2010-10-25 20:48:06 +02:00
2010-09-01 17:53:28 +02:00
# No real need to change anything below here
version = "1.0.1"
2013-09-02 17:14:07 +02:00
ok = 0
warning = 1
critical = 2
unknown = 3
2010-09-01 17:53:28 +02:00
not_present = -1
state = {}
state[not_present] = "Not Present"
state[ok] = "OK"
state[warning] = "Warning"
state[critical] = "Critical"
state[unknown] = "Unknown"
2013-09-02 17:14:07 +02:00
longserviceoutput = "\n"
perfdata = ""
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +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
2013-09-11 17:04:52 +02:00
from os import getenv, environ
import signal
2010-09-01 17:53:28 +02:00
import subprocess
2013-09-02 17:14:07 +02:00
import xmlrpclib
import httplib
# we need to set socket default timeout in case we are using the phone-home part
2010-09-08 18:07:48 +02:00
import socket
2013-09-02 17:14:07 +02:00
socket.setdefaulttimeout(5)
2010-09-01 17:53:28 +02:00
def print_help():
2013-08-21 15:50:34 +02:00
print "check_eva version %s" % version
print "This plugin checks HP EVA Array with the sssu command"
print ""
print "Usage: %s [OPTIONS]" % argv[0]
print "OPTIONS:"
2013-09-02 17:14:07 +02:00
print " [--host <host>]"
print " [--username <user>]"
print " [--password <password]"
print " [--path </path/to/sssu>]"
print " [--mode <mode>] "
print " [--test]"
print " [--timeout <timeout>]"
2013-09-02 17:14:07 +02:00
print " [--debug]"
print " [--help]"
print ""
print " Valid modes are: %s" % ', '.join(valid_modes)
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):
2013-08-21 15:50:34 +02:00
print "* Error: %s" % errortext
print_help()
print "* Error: %s" % errortext
exit(unknown)
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
def debug(debugtext):
2013-08-21 15:50:34 +02:00
global debugging
if debugging:
2013-09-02 17:14:07 +02:00
print debugtext
2010-09-01 20:45:05 +02:00
2010-09-01 17:53:28 +02:00
# parse arguments
2013-09-02 17:14:07 +02:00
arguments = argv[1:]
2010-09-01 17:53:28 +02:00
while len(arguments) > 0:
2013-09-02 17:14:07 +02:00
arg = arguments.pop(0)
2013-08-21 15:50:34 +02:00
if arg == 'invalid':
pass
elif arg == '-H' or arg == '--host':
2013-09-02 17:14:07 +02:00
hostname = arguments.pop(0)
2013-08-21 15:50:34 +02:00
elif arg == '-U' or arg == '--username':
2013-09-02 17:14:07 +02:00
username = arguments.pop(0)
2013-08-21 15:50:34 +02:00
elif arg == '-P' or arg == '--password':
password = arguments.pop(0)
elif arg == '-T' or arg == '--test':
2013-09-02 17:14:07 +02:00
testmode = 1
elif arg == '--timeout':
timeout = int(arguments.pop(0))
2013-08-21 15:50:34 +02:00
elif arg == '--path':
path = arguments.pop(0) + '/'
elif arg == '-M' or arg == '--mode':
2013-09-02 17:14:07 +02:00
mode = arguments.pop(0)
2013-08-21 15:50:34 +02:00
if mode not in valid_modes:
error("Invalid --mode %s" % arg)
elif arg == '-d' or arg == '--debug':
2013-09-02 17:14:07 +02:00
debugging = True
2013-08-21 15:50:34 +02:00
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
elif arg == '--nagios_myhostname':
nagios_myhostname = arguments.pop(0)
elif arg == '--nagios_server':
nagios_server = arguments.pop(0)
elif arg == '--nagios_port':
nagios_port = arguments.pop(0)
elif arg == '--system':
check_system = arguments.pop(0)
elif arg == '--phone-home':
do_phone_home = True
elif arg == '--proxy':
proxyserver = arguments.pop(0)
elif arg == '--escape-newlines':
escape_newlines = True
elif arg == '-h' or arg == '--help':
print_help()
exit(ok)
else:
2013-09-02 17:14:07 +02:00
error("Invalid argument %s" % arg)
2010-09-01 17:53:28 +02:00
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
def runCommand(command):
""" runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful """
2013-09-02 17:14:07 +02:00
proc = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,)
2013-08-21 15:50:34 +02:00
stdout, stderr = proc.communicate('through stdin to stdout')
if proc.returncode > 0:
2013-09-02 17:14:07 +02:00
print "Error %s: %s\n command was: '%s'" % (proc.returncode, stderr.strip(), command)
# File not found, lets print path
if proc.returncode == 127 or proc.returncode == 1:
path = getenv("PATH")
2013-08-21 15:55:57 +02:00
print "Current Path: %s" % path
2013-08-21 15:50:34 +02:00
exit(unknown)
else:
return stdout
2010-09-01 17:53:28 +02:00
def run_sssu(system=None, command="ls system full"):
"""Runs the sssu command. This one is responsible for error checking from sssu"""
2013-08-21 15:50:34 +02:00
commands = []
2013-09-02 17:14:07 +02:00
continue_on_error = "set option on_error=continue"
login = "select manager %s USERNAME=%s PASSWORD=%s" % (
hostname, username, password)
2013-08-21 15:50:34 +02:00
commands.append(continue_on_error)
commands.append(login)
2013-08-21 15:55:57 +02:00
if system is not None:
2013-08-21 15:50:34 +02:00
commands.append('select SYSTEM "%s"' % system)
commands.append(command)
commandstring = "sssu "
2013-08-21 15:55:57 +02:00
for i in commands:
commandstring += '"%s" ' % i
2013-08-21 15:50:34 +02:00
global server_side_troubleshooting
if server_side_troubleshooting == True:
commandstring = 'cat "debug/%s"' % command
2013-09-02 17:14:07 +02:00
# print mystring
# if command == "ls system full":
2013-08-21 15:50:34 +02:00
# output = runCommand("cat sssu.out")
2013-09-02 17:14:07 +02:00
# elif command == "ls disk_groups full":
2013-08-21 15:50:34 +02:00
# output = runCommand("cat ls_disk*")
2013-09-02 17:14:07 +02:00
# elif command == "ls controller full":
2013-08-21 15:50:34 +02:00
# output = runCommand("cat ls_controller")
2013-09-02 17:14:07 +02:00
# else:
2013-08-21 15:50:34 +02:00
# print "What command is this?", command
# exit(unknown)
output = runCommand(commandstring)
2013-09-02 17:14:07 +02:00
debug(commandstring)
2013-08-21 15:50:34 +02:00
output = output.split('\n')
2013-09-02 17:14:07 +02:00
# Lets process the top few results from the sssu command. Make sure the
# results make sense
2013-08-21 15:50:34 +02:00
error = 0
2013-09-02 17:14:07 +02:00
if output.pop(0).strip() != '':
error = 1
if output.pop(0).strip() != '':
error = 2
if output.pop(0).strip().find('SSSU for HP') != 0:
error = 3
2013-09-02 17:14:07 +02:00
if output.pop(0).strip().find('Version:') != 0:
error = 4
2013-09-02 17:14:07 +02:00
if output.pop(0).strip().find('Build:') != 0:
error = 5
2013-09-02 17:14:07 +02:00
if output.pop(0).strip().find('NoSystemSelected> ') != 0:
error = 6
2013-08-21 15:50:34 +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
str_buffer = ""
2013-08-21 15:50:34 +02:00
for i in output:
str_buffer = str_buffer + i + "\n"
2013-08-21 15:50:34 +02:00
if i.find('Error') > -1:
print "This is the command i was trying to execute: %s" % i
error = 1
2013-09-02 17:14:07 +02:00
if i.find('information:') > 0:
break
2013-08-21 15:50:34 +02:00
if error > 0:
print "Error running the sssu command: " + str(error)
2013-08-21 15:50:34 +02:00
print commandstring
print str_buffer
2013-08-21 15:50:34 +02:00
exit(unknown)
objects = []
current_object = None
2013-08-21 15:50:34 +02:00
for line in output:
if len(line) == 0:
continue
line = line.strip()
tmp = line.split()
if len(tmp) == 0:
if current_object:
2013-09-02 17:14:07 +02:00
if not current_object['master'] in objects:
objects.append(current_object['master'])
current_object = None
2013-08-21 15:50:34 +02:00
continue
key = tmp[0].strip()
2013-09-02 17:14:07 +02:00
if current_object and not current_object['master'] in objects:
objects.append(current_object['master'])
2013-08-21 15:50:34 +02:00
if key == 'object':
current_object = {}
current_object['master'] = current_object
2013-08-21 15:50:34 +02:00
if key == 'controllertemperaturestatus':
current_object = current_object['master']
2013-08-21 15:50:34 +02:00
if key == 'iomodules':
key = 'modules'
2013-09-02 17:14:07 +02:00
# if key in subitems.values():
2013-08-21 15:50:34 +02:00
# object['master'][key] = []
if key in subitems.keys():
mastergroup = subitems[key]
master = current_object['master']
current_object = {}
current_object['object_type'] = key
current_object['master'] = master
if not current_object['master'].has_key(mastergroup):
current_object['master'][mastergroup] = []
current_object['master'][mastergroup].append(current_object)
2013-08-21 15:50:34 +02:00
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 current_object.has_key(key):
2013-09-02 17:14:07 +02:00
value = ' '.join(tmp[2:]).strip()
current_object[key] = value
2013-08-21 15:50:34 +02:00
# Check if we were instructed to check only one eva system
global check_system
2013-08-21 15:55:57 +02:00
if command == "ls system full" and check_system is not None:
2013-08-21 15:50:34 +02:00
tmp_objects = []
for i in objects:
if i['objectname'] == check_system:
2013-09-02 17:14:07 +02:00
tmp_objects.append(i)
2013-08-21 15:50:34 +02:00
objects = tmp_objects
return objects
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
def end(summary, perfdata, longserviceoutput, nagios_state):
2013-08-21 15:50:34 +02:00
global show_longserviceoutput
global show_perfdata
global nagios_server
global do_phone_home
global nagios_port
global nagios_myhostname
global hostname
global mode
global escape_newlines
global check_system
2013-09-02 17:14:07 +02:00
message = "%s - %s" % (state[nagios_state], summary)
2013-08-21 15:50:34 +02:00
if show_perfdata:
2013-09-02 17:14:07 +02:00
message = "%s | %s" % (message, perfdata)
2013-08-21 15:50:34 +02:00
if show_longserviceoutput:
2013-09-02 17:14:07 +02:00
message = "%s\n%s" % (message, longserviceoutput.strip())
2013-08-21 15:50:34 +02:00
if escape_newlines == True:
lines = message.split('\n')
message = '\\n'.join(lines)
2013-09-02 17:14:07 +02:00
debug("do_phone_home = %s" % do_phone_home)
2013-08-21 15:50:34 +02:00
if do_phone_home == True:
try:
if nagios_myhostname is None:
2013-09-02 17:14:07 +02:00
if environ.has_key('HOSTNAME'):
2013-08-21 15:50:34 +02:00
nagios_myhostname = environ['HOSTNAME']
2013-09-02 17:14:07 +02:00
elif environ.has_key('COMPUTERNAME'):
2013-08-21 15:50:34 +02:00
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
2013-09-02 17:14:07 +02:00
)
except Exception:
pass
2013-08-21 15:50:34 +02:00
except:
raise
print message
exit(nagios_state)
2013-09-02 17:14:07 +02:00
2010-10-06 16:56:25 +02:00
class ProxiedTransport(xmlrpclib.Transport):
2013-09-02 17:14:07 +02:00
2013-08-21 15:50:34 +02:00
def set_proxy(self, proxy):
self.proxy = proxy
2013-09-02 17:14:07 +02:00
2013-08-21 15:50:34 +02:00
def make_connection(self, host):
self.realhost = host
h = httplib.HTTP(self.proxy)
return h
2013-09-02 17:14:07 +02:00
2013-08-21 15:50:34 +02:00
def send_request(self, connection, handler, request_body):
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
2013-09-02 17:14:07 +02:00
2013-08-21 15:50:34 +02:00
def send_host(self, connection, host):
connection.putheader('Host', self.realhost)
2010-10-06 16:56:25 +02:00
2013-09-02 17:14:07 +02:00
def phone_home(nagios_server, nagios_port, status, message, hostname=None, servicename=None, system=None):
"""phone_home: Sends results to remote nagios server via python xml-rpc"""
2013-08-21 15:55:57 +02:00
debug("phoning home: %s" % servicename)
2013-08-21 15:50:34 +02:00
if system is not None:
servicename = str(servicename) + str(system)
2013-09-02 17:14:07 +02:00
uri = "http://%s:%s" % (nagios_server, nagios_port)
2013-08-21 15:50:34 +02:00
global proxyserver
2013-08-21 15:55:57 +02:00
if proxyserver is not None:
2013-08-21 15:50:34 +02:00
p = ProxiedTransport()
p.set_proxy(proxyserver)
2013-09-02 17:14:07 +02:00
s = xmlrpclib.Server(uri, transport=p)
2013-08-21 15:50:34 +02:00
else:
2013-09-02 17:14:07 +02:00
s = xmlrpclib.ServerProxy(uri)
2013-08-21 15:50:34 +02:00
s.nagiosupdate(hostname, servicename, status, message)
return 0
2010-09-08 16:37:32 +02:00
2013-09-02 17:14:07 +02:00
2010-09-01 20:45:05 +02:00
def check_systems():
2013-09-02 17:14:07 +02:00
summary = ""
perfdata = ""
# longserviceoutput="\n"
2013-08-21 15:50:34 +02:00
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
2013-08-21 15:55:57 +02:00
summary += " %s=%s " % (name, operationalstate)
2013-08-21 15:50:34 +02:00
# Collect the performance data
interesting_perfdata = 'totalstoragespace|usedstoragespace|availablestoragespace'
2013-09-02 17:14:07 +02:00
perfdata += get_perfdata(
i, interesting_perfdata.split('|'), identifier="%s_" % name)
2013-08-21 15:50:34 +02:00
# Collect extra info for longserviceoutput
2013-09-02 17:14:07 +02:00
longoutput("%s = %s (%s)\n" %
(i['objectname'], i['operationalstate'], i['operationalstatedetail']))
2013-08-21 15:50:34 +02:00
interesting_fields = 'licensestate|systemtype|firmwareversion|nscfwversion|totalstoragespace|usedstoragespace|availablestoragespace'
for x in interesting_fields.split('|'):
2013-09-02 17:14:07 +02:00
longoutput("- %s = %s \n" % (x, i[x]))
longoutput("\n")
2013-09-02 17:14:07 +02:00
end(summary, perfdata, longserviceoutput, nagios_state)
2010-09-01 17:53:28 +02:00
def get_perfdata(my_object, interesting_fields, identifier=""):
2013-08-21 15:50:34 +02:00
perfdata = ""
for i in interesting_fields:
2013-09-02 17:14:07 +02:00
if i == '':
continue
perfdata += "'%s%s'=%s " % (identifier, i, my_object[i])
2013-08-21 15:50:34 +02:00
return perfdata
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
2010-09-01 22:35:47 +02:00
def add_perfdata(text):
2013-08-21 15:50:34 +02:00
global perfdata
text = text.strip()
2013-08-21 15:55:57 +02:00
perfdata += " %s " % text
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
def longoutput(text):
2013-08-21 15:50:34 +02:00
global longserviceoutput
longserviceoutput = longserviceoutput + text
2013-09-02 17:14:07 +02:00
def get_longserviceoutput(my_object, interesting_fields):
2013-08-21 15:50:34 +02:00
longserviceoutput = ""
for i in interesting_fields:
longserviceoutput += "%s = %s \n" % (i, my_object[i])
2013-08-21 15:50:34 +02:00
return longserviceoutput
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
def check_operationalstate(my_object, print_failed_objects=False, namefield='objectname', detailfield='operationalstatedetail', statefield='operationalstate', valid_states=None):
2013-08-21 15:55:57 +02:00
if not valid_states:
2013-09-02 17:14:07 +02:00
valid_states = ['good']
if not my_object.has_key(detailfield):
detailfield = statefield
if not my_object.has_key(statefield):
2013-08-21 15:50:34 +02:00
if print_failed_objects:
2013-09-02 17:14:07 +02:00
longoutput("- Warning, %s does not have any '%s'" %
(my_object[namefield], statefield))
2013-08-21 15:50:34 +02:00
return warning
if my_object[statefield] not in valid_states:
2013-08-21 15:50:34 +02:00
if print_failed_objects:
2013-09-02 17:14:07 +02:00
longoutput("- Warning, %s=%s (%s)\n" %
(my_object[namefield], my_object['operationalstate'], my_object[detailfield]))
2013-08-21 15:50:34 +02:00
return warning
2013-09-02 17:14:07 +02:00
debug("OK, %s=%s (%s)\n" %
(my_object[namefield], my_object['operationalstate'], my_object[detailfield]))
2013-08-21 15:50:34 +02:00
return ok
2010-09-01 17:53:28 +02:00
2013-09-02 17:14:07 +02:00
def check_generic(command="ls disk full", namefield="objectname", perfdata_fields=None, longserviceoutputfields=None, detailedsummary=False):
2013-08-21 15:55:57 +02:00
if not perfdata_fields:
2013-09-02 12:50:48 +02:00
perfdata_fields = []
2013-08-21 15:55:57 +02:00
if not longserviceoutputfields:
longserviceoutputfields = []
2013-08-21 15:50:34 +02:00
global perfdata
nagios_state = ok
systems = run_sssu()
objects = []
if command == 'ls system full':
objects = systems
2013-09-02 17:14:07 +02:00
for i in systems:
i['systemname'] = '' # i['objectname']
2013-08-21 15:50:34 +02:00
else:
for i in systems:
result = run_sssu(system=i['objectname'], command=command)
for x in result:
x['systemname'] = i['objectname']
2013-09-02 17:14:07 +02:00
objects.append(x)
2013-08-21 15:50:34 +02:00
summary = "%s objects found " % len(objects)
2013-09-02 17:14:07 +02:00
usedstoragespacegb = 0
occupancyalarmlvel = 0
warninggb = 0
2013-08-21 15:50:34 +02:00
for i in objects:
systemname = i['systemname']
# Some versions of commandview use "objectname" instead of namefield
2013-09-02 17:14:07 +02:00
if i.has_key(namefield):
2013-08-21 15:50:34 +02:00
objectname = i[namefield]
else:
objectname = i['objectname']
2013-09-02 17:14:07 +02:00
# Some versions of CV also return garbage objects, luckily it is easy
# to find these
2013-08-21 15:50:34 +02:00
if i.has_key('objecttype') and i['objecttype'] == 'typenotset':
2013-09-02 17:14:07 +02:00
longoutput(
"Object %s was skipped because objecttype == typenotset\n" % objectname)
2013-08-21 15:50:34 +02:00
continue
# Lets see if this object is working
2013-09-02 17:14:07 +02:00
nagios_state = max(check_operationalstate(i), nagios_state)
2013-08-21 15:50:34 +02:00
# Lets add to the summary
2013-09-02 17:14:07 +02:00
if i['operationalstate'] != 'good' or detailedsummary == True:
summary += " %s/%s=%s " % (
systemname, objectname, i['operationalstate'])
2013-08-21 15:50:34 +02:00
# Lets get some perfdata
2013-09-02 17:14:07 +02:00
identifier = "%s/%s_" % (systemname, objectname)
2013-08-21 15:50:34 +02:00
i['identifier'] = identifier
for field in perfdata_fields:
2013-09-02 17:14:07 +02:00
if field == '':
continue
add_perfdata("'%s%s'=%s " %
(identifier, field, i.get(field, None)))
2013-08-21 15:50:34 +02:00
# Disk group gets a special perfdata treatment
if command == "ls disk_group full":
2013-09-02 17:14:07 +02:00
totalstoragespacegb = float(i['totalstoragespacegb'])
usedstoragespacegb = float(i['usedstoragespacegb'])
occupancyalarmlvel = float(i['occupancyalarmlevel'])
warninggb = totalstoragespacegb * occupancyalarmlvel / 100
2013-09-02 17:14:07 +02:00
add_perfdata(" '%sdiskusage'=%s;%s;%s " %
(identifier, usedstoragespacegb, warninggb, totalstoragespacegb))
2013-08-21 15:50:34 +02:00
# Long Serviceoutput
# There are usually to many disks for nagios to display. Skip.
if command != "ls disk full":
2013-09-02 17:14:07 +02:00
longoutput("\n%s/%s = %s (%s)\n" %
(systemname, objectname, i['operationalstate'], i['operationalstatedetail']))
2013-08-21 15:50:34 +02:00
2013-09-02 17:14:07 +02:00
# If diskgroup has a problem because it is over allocated. Lets inform
# about that
2013-08-21 15:50:34 +02:00
if command == "ls disk_group full" and usedstoragespacegb > warninggb:
2013-09-02 17:14:07 +02:00
longoutput(
"- %s - diskgroup usage is over %s%% threshold !\n" %
(state[warning], occupancyalarmlvel))
2013-08-21 15:50:34 +02:00
# If a disk has a problem, lets display some extra info on it
elif command == "ls disk full" and i['operationalstate'] != 'good':
2013-09-02 17:14:07 +02:00
longoutput("Warning - %s=%s (%s)\n" %
(i['diskname'], i['operationalstate'], i['operationalstatedetail']))
fields = "modelnumber firmwareversion serialnumber failurepredicted diskdrivetype".split(
)
2013-08-21 15:50:34 +02:00
for field in fields:
2013-09-02 17:14:07 +02:00
longoutput("- %s = %s\n" % (field, i[field]))
2013-08-21 15:50:34 +02:00
nagios_state = max(nagios_state, check_multiple_objects(i, 'sensors'))
nagios_state = max(nagios_state, check_multiple_objects(i, 'fans'))
2013-09-02 17:14:07 +02:00
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'))
2013-08-21 15:50:34 +02:00
nagios_state = max(nagios_state, check_multiple_objects(i, 'modules'))
for x in longserviceoutputfields:
2013-09-02 17:14:07 +02:00
if i.has_key(x):
longoutput("- %s = %s\n" % (x, i[x]))
2014-01-31 15:06:04 +01:00
end(summary, perfdata, longserviceoutput, nagios_state)
2013-08-21 15:50:34 +02:00
2010-09-01 20:45:05 +02:00
def check_multiple_objects(my_object, name):
2013-08-21 15:50:34 +02:00
item_status = not_present
if my_object.has_key(name):
2013-08-21 15:50:34 +02:00
item_status = not_present
2013-09-02 17:14:07 +02:00
valid_states = ['good']
namefield = "name"
2013-08-21 15:50:34 +02:00
detailfield = 'operationalstatedetail'
2010-09-01 22:35:47 +02:00
2013-08-21 15:50:34 +02:00
if name == 'fans' or name == 'sensors':
2013-09-02 17:14:07 +02:00
valid_states = [
'good', 'notavailable', 'unsupported', 'notinstalled']
2013-08-21 15:50:34 +02:00
elif name == 'fibrechannelports':
2013-09-02 17:14:07 +02:00
valid_states.append('notinstalled')
num_items = len(my_object[name])
for item in my_object[name]:
2013-09-02 17:14:07 +02:00
stat = check_operationalstate(
item, print_failed_objects=True, namefield=namefield, valid_states=valid_states, detailfield=detailfield)
item_status = max(stat, item_status)
longoutput('- %s on %s (%s detected)\n' %
(state[item_status], name, num_items))
add_perfdata(" '%s%s'=%s" %
(my_object['identifier'], name, num_items))
2013-08-21 15:50:34 +02:00
return item_status
2010-09-01 20:45:05 +02:00
2010-09-01 17:53:28 +02:00
def check_controllers():
2013-09-02 17:14:07 +02:00
perfdata = ""
# longserviceoutput="\n"
2013-08-21 15:50:34 +02:00
nagios_state = ok
systems = run_sssu()
2013-09-02 17:14:07 +02:00
controllers = []
2013-08-21 15:50:34 +02:00
for i in systems:
result = run_sssu(system=i['objectname'], command="ls controller full")
for controller in result:
controller['systemname'] = i['objectname']
2013-09-02 17:14:07 +02:00
controllers.append(controller)
2013-08-21 15:50:34 +02:00
summary = "%s objects found " % len(controllers)
for i in controllers:
systemname = i['systemname']
if i.has_key('controllername'):
controllername = i['controllername']
else:
controllername = i['objectname']
# Lets see if this controller is working
2013-09-02 17:14:07 +02:00
nagios_state = max(check_operationalstate(i), nagios_state)
2013-08-21 15:50:34 +02:00
# Lets add to the summary
if not i.has_key('operationalstate'):
2013-08-21 15:55:57 +02:00
summary += " %s does not have any operationalstate " % controllername
2013-09-02 17:14:07 +02:00
nagios_state = max(unknown, nagios_state)
2013-08-21 15:50:34 +02:00
continue
2013-09-02 17:14:07 +02:00
elif i['operationalstate'] != 'good':
summary += " %s/%s=%s " % (
systemname, controllername, i['operationalstate'])
2013-08-21 15:50:34 +02:00
# Lets get some perfdata
interesting_fields = "controllermainmemory"
2013-09-02 17:14:07 +02:00
identifier = "%s/%s_" % (systemname, controllername)
perfdata += get_perfdata(
i, interesting_fields.split('|'), identifier=identifier)
2013-08-21 15:50:34 +02:00
# Long Serviceoutput
#longserviceoutput = longserviceoutput + get_longserviceoutput(i, interesting_fields.split('|') )
#longserviceoutput = longserviceoutput + "\n%s/%s\n"%(systemname,controllername)
2013-09-02 17:14:07 +02:00
longoutput("\n%s/%s = %s (%s)\n" %
(systemname, controllername, i['operationalstate'], i['operationalstatedetail']))
longoutput("- firmwareversion = %s \n" % (i['firmwareversion']))
longoutput("- serialnumber = %s \n" % (i['serialnumber']))
2013-08-21 15:50:34 +02:00
2013-09-11 17:04:52 +02:00
controllertemperaturestatus = not_present
2013-08-21 15:50:34 +02:00
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
if i.has_key("controllertemperaturestatus"):
if i['controllertemperaturestatus'] == 'normal':
controllertemperaturestatus = ok
else:
controllertemperaturestatus = warning
# Process the subsensors
for hostport in i['hostports']:
#long(" %s = %s\n" % (hostport['portname'], hostport['operationalstate']))
2013-09-02 17:14:07 +02:00
hostportstate = max(hostportstate, ok)
2013-08-21 15:50:34 +02:00
if hostport['operationalstate'] != 'good':
2013-09-11 17:04:52 +02:00
hostportstate = max(warning, hostportstate)
2013-09-02 17:14:07 +02:00
message = "Hostport %s state = %s\n" % (
hostport['portname'], hostport['operationalstate'])
longoutput(message)
2013-08-21 15:50:34 +02:00
if i.has_key('fans'):
for fan in i['fans']:
2013-09-02 17:14:07 +02:00
fanstate = max(fanstate, ok)
2013-08-21 15:50:34 +02:00
#long(" %s = %s\n" % (fan['fanname'], fan['status']))
2013-09-02 17:14:07 +02:00
if fan.has_key('status'):
status = fan['status']
elif fan.has_key('installstatus'):
status = fan['installstatus']
2013-08-21 15:50:34 +02:00
if status != 'normal' and status != 'yes':
2013-09-02 17:14:07 +02:00
fanstate = max(warning, fanstate)
longoutput("Fan %s status = %s\n" %
(fan['fanname'], status))
2013-08-21 15:50:34 +02:00
if i.has_key('powersources'):
for source in i['powersources']:
2013-09-02 17:14:07 +02:00
source_state = max(source_state, ok)
if not source.has_key('status'):
continue
2013-08-21 15:50:34 +02:00
if source['state'] != 'good':
2013-09-02 17:14:07 +02:00
source_state = max(warning, source_state)
longoutput("Powersource %s status = %s\n" %
(source['type'], source['state']))
2013-08-21 15:50:34 +02:00
if i.has_key('modules'):
for module in i['modules']:
2013-09-02 17:14:07 +02:00
module_state = max(module_state, ok)
if module['operationalstate'] not in ('good', 'not_present'):
module_state = max(warning, module_state)
longoutput("Battery Module %s status = %s\n" %
(module['name'], module['operationalstate']))
2013-08-21 15:50:34 +02:00
2013-09-02 17:14:07 +02:00
for i in (fanstate, hostportstate, sensorstate, source_state, module_state, cache_state, controllertemperaturestatus):
2013-08-21 15:50:34 +02:00
nagios_state = max(nagios_state, i)
2013-09-02 17:14:07 +02:00
longoutput("- %s on fans\n" % (state[fanstate]))
longoutput("- %s on cachememory\n" % (state[cache_state]))
longoutput("- %s on temperature\n" %
(state[controllertemperaturestatus]))
longoutput("- %s on hostports\n" % (state[hostportstate]))
longoutput("- %s on sensors\n" % (state[sensorstate]))
longoutput("- %s on powersupplies\n" % (state[source_state]))
longoutput("- %s on batterymodules\n" % (state[module_state]))
2013-08-21 15:50:34 +02:00
longoutput('\n')
2013-09-02 17:14:07 +02:00
end(summary, perfdata, longserviceoutput, nagios_state)
2010-09-01 17:53:28 +02:00
2010-09-02 20:07:17 +02:00
def set_path():
2013-08-21 15:50:34 +02:00
global path
current_path = getenv('PATH')
if path == '':
2013-09-02 17:14:07 +02:00
if current_path.find('C:\\') > -1: # We are on this platform
2013-08-21 15:50:34 +02:00
path = ";C:\\Program Files\\Hewlett-Packard\\Sanworks\\Element Manager for StorageWorks HSV"
else:
path = ":/usr/local/bin"
2013-09-02 17:14:07 +02:00
current_path = "%s%s" % (current_path, path)
2013-08-21 15:50:34 +02:00
environ['PATH'] = current_path
2010-09-02 20:07:17 +02:00
set_path()
# Create an alarm so that plugin can exit properly if timeout occurs
exit_with_timeout = lambda x, y: error("Timeout of %s seconds exceeded" % timeout)
signal.signal(signal.SIGALRM, exit_with_timeout)
signal.alarm(timeout)
2010-09-01 20:45:05 +02:00
if mode == 'check_systems':
2013-09-02 17:14:07 +02:00
perfdata_fields = 'totalstoragespace usedstoragespace availablestoragespace'.split(
)
longserviceoutputfields = 'licensestate systemtype firmwareversion nscfwversion totalstoragespace usedstoragespace availablestoragespace'.split(
)
2013-08-21 15:50:34 +02:00
command = "ls system full"
2013-09-02 17:14:07 +02:00
namefield = "objectname"
check_generic(command=command, namefield=namefield,
longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields)
2010-09-01 17:53:28 +02:00
elif mode == 'check_controllers':
2013-08-21 15:50:34 +02:00
check_controllers()
2010-09-01 17:53:28 +02:00
elif mode == 'check_diskgroups':
2013-08-21 15:50:34 +02:00
command = "ls disk_group full"
2013-09-02 17:14:07 +02:00
namefield = 'diskgroupname'
longserviceoutputfields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel".split(
)
perfdata_fields = "totaldisks".split()
check_generic(command=command, namefield=namefield,
longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields)
2010-09-01 20:45:05 +02:00
elif mode == 'check_disks':
2013-09-02 17:14:07 +02:00
check_generic(command="ls disk full", namefield="objectname")
elif mode == 'check_diskshelfs' or mode == 'check_diskshelves':
2013-09-02 17:14:07 +02:00
check_generic(command="ls diskshelf full", namefield="diskshelfname",
longserviceoutputfields=[], perfdata_fields=[])
2010-09-01 17:53:28 +02:00
else:
2013-08-21 15:50:34 +02:00
print "* Error: Mode %s not found" % mode
print_help()
print "* Error: Mode %s not found" % mode
exit(unknown)