1
0
mirror of https://github.com/opinkerfi/nagios-plugins.git synced 2024-11-22 18:33:45 +01:00

Code cleanup, more perfdata added

This commit is contained in:
Páll Guðjón Sigurðsson 2010-09-01 20:35:47 +00:00
parent f440ab19bc
commit 86290aa91a

View File

@ -27,6 +27,7 @@ state[critical] = "Critical"
state[unknown] = "Unknown" state[unknown] = "Unknown"
longserviceoutput="\n" longserviceoutput="\n"
perfdata=""
valid_modes = ( "check_systems", "check_controllers", "check_diskgroups","check_disks", "check_diskshelfs") valid_modes = ( "check_systems", "check_controllers", "check_diskgroups","check_disks", "check_diskshelfs")
@ -102,6 +103,8 @@ subitems['hostport'] = 'hostports'
subitems['module'] = 'modules' subitems['module'] = 'modules'
subitems['sensor'] = 'sensors' subitems['sensor'] = 'sensors'
subitems['powersupply'] = 'powersupplies' subitems['powersupply'] = 'powersupplies'
subitems['bus'] = 'communicationbuses'
subitems['port'] = 'fibrechannelports'
'''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful''' '''runCommand: Runs command from the shell prompt. Exit Nagios style if unsuccessful'''
@ -259,6 +262,10 @@ def get_perfdata(object, interesting_fields, identifier=""):
perfdata = perfdata + "'%s%s'=%s " % (identifier, i, object[i]) perfdata = perfdata + "'%s%s'=%s " % (identifier, i, object[i])
return perfdata return perfdata
def add_perfdata(text):
global perfdata
text = text.strip()
perfdata = perfdata + " %s " % (text)
def long(text): def long(text):
global longserviceoutput global longserviceoutput
@ -269,7 +276,8 @@ def get_longserviceoutput(object, interesting_fields):
longserviceoutput = longserviceoutput + "%s = %s \n" %(i, object[i]) longserviceoutput = longserviceoutput + "%s = %s \n" %(i, object[i])
return longserviceoutput return longserviceoutput
def check_operationalstate(object, print_failed_objects=False,namefield='objectname',detailfield='operationalstate',valid_states=['good']): 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 object['operationalstate'] not in valid_states: if object['operationalstate'] not in valid_states:
if print_failed_objects: if print_failed_objects:
long("Warning, %s=%s (%s)\n" % ( object[namefield], object['operationalstate'], object[detailfield] )) long("Warning, %s=%s (%s)\n" % ( object[namefield], object['operationalstate'], object[detailfield] ))
@ -278,46 +286,17 @@ def check_operationalstate(object, print_failed_objects=False,namefield='objectn
return ok return ok
def check_diskgroups():
summary=""
perfdata=""
nagios_state = ok
systems = run_sssu()
objects = []
for i in systems:
result = run_sssu(system=i['objectname'], command="ls disk_group full")
for x in result:
x['systemname'] = i['objectname']
objects.append( x )
for i in objects:
systemname = i['systemname']
objectname = i['diskgroupname']
# Lets see if this object is working
nagios_state = max( check_operationalstate(i), nagios_state )
# Lets add to the summary
summary = summary + " %s/%s=%s " %(systemname,objectname, i['operationalstate'])
# Lets get some perfdata
interesting_fields = "totaldisks|totalstoragespacegb|usedstoragespacegb|occupancyalarmlevel"
identifier = "%s/%s_" % (systemname,objectname)
perfdata = perfdata + get_perfdata(i, interesting_fields.split('|'), identifier=identifier)
# Long Serviceoutput
interesting_fields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel"
long( "\n%s/%s = %s (%s)\n"%(systemname,objectname,i['operationalstate'], i['operationalstatedetail']) )
for x in interesting_fields.split():
long( "- %s = %s\n" % (x, i[x]))
end(summary,perfdata,longserviceoutput,nagios_state)
def check_generic(command="ls disk full",namefield="objectname", perfdata_fields=[], longserviceoutputfields=[], detailedsummary=False): def check_generic(command="ls disk full",namefield="objectname", perfdata_fields=[], longserviceoutputfields=[], detailedsummary=False):
summary="" summary=""
perfdata="" global perfdata
nagios_state = ok nagios_state = ok
systems = run_sssu() systems = run_sssu()
objects = [] objects = []
if command == 'ls system full':
objects = systems
for i in systems: i['systemname'] = '' #i['objectname']
else:
for i in systems: for i in systems:
result = run_sssu(system=i['objectname'], command=command) result = run_sssu(system=i['objectname'], command=command)
for x in result: for x in result:
@ -338,51 +317,69 @@ def check_generic(command="ls disk full",namefield="objectname", perfdata_fields
# Lets get some perfdata # Lets get some perfdata
identifier = "%s/%s_" % (systemname,objectname) identifier = "%s/%s_" % (systemname,objectname)
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
if command == "ls disk_group full": if command == "ls disk_group full":
totalstoragespacegb= float( i['totalstoragespacegb'] ) totalstoragespacegb= float( i['totalstoragespacegb'] )
usedstoragespacegb= float ( i['usedstoragespacegb'] ) usedstoragespacegb= float ( i['usedstoragespacegb'] )
occupancyalarmlvel = float( i['occupancyalarmlevel'] ) occupancyalarmlvel = float( i['occupancyalarmlevel'] )
warninggb= totalstoragespacegb * occupancyalarmlvel / 100 warninggb= totalstoragespacegb * occupancyalarmlvel / 100
perfdata = perfdata + " '%sdiskusage'=%s;%s;%s "% (identifier, usedstoragespacegb,warninggb,totalstoragespacegb) add_perfdata( " '%sdiskusage'=%s;%s;%s "% (identifier, usedstoragespacegb,warninggb,totalstoragespacegb) )
for field in perfdata_fields:
if field == '': continue
perfdata = perfdata + "'%s%s'=%s " % (identifier, field, i[field])
# Long Serviceoutput # Long Serviceoutput
#interesting_fields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel"
if command == "ls disk full": # There are usually to many disks for nagios to display. Skip.
pass if command != "ls disk full":
else:
long( "\n%s/%s = %s (%s)\n"%(systemname,objectname,i['operationalstate'], i['operationalstatedetail']) ) long( "\n%s/%s = %s (%s)\n"%(systemname,objectname,i['operationalstate'], i['operationalstatedetail']) )
# If diskgroup has a problem because it is over allocated. Lets inform about that
if command == "ls disk_group full" and usedstoragespacegb > warninggb: if command == "ls disk_group full" and usedstoragespacegb > warninggb:
long("- %s - diskgroup usage is over %s%% threshold !\n" % (state[warning], occupancyalarmlvel) ) long("- %s - diskgroup usage is over %s%% threshold !\n" % (state[warning], occupancyalarmlvel) )
# If a disk has a problem, lets display some extra info on it
elif command == "ls disk full" and i['operationalstate'] != 'good': elif command == "ls disk full" and i['operationalstate'] != 'good':
long( "Warning - %s=%s (%s)\n" % (i['diskname'], i['operationalstate'], i['operationalstatedetail'] )) long( "Warning - %s=%s (%s)\n" % (i['diskname'], i['operationalstate'], i['operationalstatedetail'] ))
fields="modelnumber firmwareversion serialnumber failurepredicted diskdrivetype".split() fields="modelnumber firmwareversion serialnumber failurepredicted diskdrivetype".split()
for field in fields: for field in fields:
long( "- %s = %s\n" % (field, i[field]) ) long( "- %s = %s\n" % (field, i[field]) )
if i.has_key('powersupplies'): # disk_shelf has this
powersupply_status = not_present
for powersupply in i['powersupplies']:
powersupply_status = max( check_operationalstate( powersupply, print_failed_objects=True, namefield='name', detailfield='name'), powersupply_status )
nagios_state = max(nagios_state, powersupply_status)
long('- %s on powersupplies\n'% state[powersupply_status])
if i.has_key('sensors'): # disk_shelf has this
sensor_status = not_present
for sensor in i['sensors']:
stat = check_operationalstate( sensor,print_failed_objects=True, namefield='name', valid_states=['good','notavailable','unsupported','notinstalled'])
sensor_status = max( stat, sensor_status )
nagios_state = max(nagios_state, sensor_status)
long('- %s on sensors\n'% state[sensor_status])
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'))
for x in longserviceoutputfields: for x in longserviceoutputfields:
long( "- %s = %s\n" % (x, i[x])) long( "- %s = %s\n" % (x, i[x]))
end(summary,perfdata,longserviceoutput,nagios_state) end(summary,perfdata,longserviceoutput,nagios_state)
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']
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
def check_controllers(): def check_controllers():
@ -489,7 +486,12 @@ def check_controllers():
end(summary,perfdata,longserviceoutput,nagios_state) end(summary,perfdata,longserviceoutput,nagios_state)
if mode == 'check_systems': if mode == 'check_systems':
check_systems() 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
elif mode == 'check_controllers': elif mode == 'check_controllers':
check_controllers() check_controllers()
elif mode == 'check_diskgroups': elif mode == 'check_diskgroups':
@ -497,7 +499,6 @@ elif mode == 'check_diskgroups':
namefield='diskgroupname' namefield='diskgroupname'
longserviceoutputfields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel".split() longserviceoutputfields = "totaldisks levelingstate levelingprogress totalstoragespacegb usedstoragespacegb occupancyalarmlevel".split()
perfdata_fields="totaldisks".split() perfdata_fields="totaldisks".split()
check_generic(command=command,namefield=namefield,longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields) check_generic(command=command,namefield=namefield,longserviceoutputfields=longserviceoutputfields, perfdata_fields=perfdata_fields)
elif mode == 'check_disks': elif mode == 'check_disks':
check_generic(command="ls disk full",namefield="objectname") check_generic(command="ls disk full",namefield="objectname")