1
0
mirror of https://github.com/Napsty/check_esxi_hardware.git synced 2026-02-06 15:15:20 +01:00

21 Commits

Author SHA1 Message Date
Napsty
8836e8ecea Allow regular expressions from ignore list (-r) 2019-05-10 09:59:10 +02:00
Napsty
8bcf7309d9 Allow regular expressions from ignore list (-r) 2019-05-03 17:09:34 +02:00
Claudio Kuenzler
df56d7373d Merge pull request #30 from Napsty/python3
Python3 compatibility
2018-10-02 06:58:00 +02:00
Claudio Kuenzler
6aebd1a4bb Added future statement for print function 2018-10-01 12:39:10 +02:00
Claudio Kuenzler
96aced6377 Python3 compatibility 2018-10-01 11:15:59 +02:00
Claudio Kuenzler
9f8b22a393 version bump 2018-04-11 07:35:09 +02:00
Claudio Kuenzler
413dac781b Merge pull request #21 from peternewman/master
Throw an unknown if we can't fetch the data for some reason
2018-04-11 07:33:28 +02:00
Peter Newman
21e0c2b3ed Fix a whitespace issue 2018-04-10 14:37:18 +01:00
Peter Newman
b758ee20df Merge pull request #1 from Napsty/master
Resync with master
2018-04-10 14:36:13 +01:00
Claudio Kuenzler
277206abc7 Merge pull request #28 from Napsty/pywbemversion
Try to use internal pywbem function to determine version
2018-03-29 09:19:41 +02:00
Claudio Kuenzler
bd61850aa5 Try to use internal pywbem function to determine version 2018-03-29 09:15:07 +02:00
Claudio Kuenzler
ccb315d2d7 Merge pull request #23 from Napsty/lcd
Option --no-lcd
2017-09-05 21:08:58 +02:00
Claudio Kuenzler
575c4b47a7 Ready for new version 2017-09-05 21:06:53 +02:00
Claudio Kuenzler
0e62849ffb Define lcd ignore list before checking classes 2017-09-02 11:24:37 +02:00
Claudio Kuenzler
9ea8ba5967 Corected lcd condition 2017-09-02 11:21:31 +02:00
Claudio Kuenzler
7d4a85d0f3 Update check_esxi_hardware.py 2017-09-01 16:49:19 +02:00
Claudio Kuenzler
ff33e0a7b8 Debugging --no-lcd 2017-09-01 07:05:54 +02:00
Claudio Kuenzler
cec24c19bd Added --no-lcd option 2017-08-31 21:19:34 +02:00
Peter Newman
db0ffb7a05 Throw another unknown if we can't fetch the data elsewhere for some reason 2017-01-25 10:48:19 +00:00
Peter Newman
3566f03ecb SPaG 2017-01-24 18:06:35 +00:00
Peter Newman
ecf93a695e Throw an unknown if we can't fetch the data for some reason 2017-01-24 17:57:28 +00:00
2 changed files with 87 additions and 33 deletions

View File

@@ -8,4 +8,4 @@ This is the public git repository for development of the plugin.
Documentation + Production Ready Plugin Documentation + Production Ready Plugin
------------- -------------
Please refer to http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.php Please refer to https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php

View File

@@ -24,7 +24,7 @@
# Copyright (c) 2008 David Ligeret # Copyright (c) 2008 David Ligeret
# Copyright (c) 2009 Joshua Daniel Franklin # Copyright (c) 2009 Joshua Daniel Franklin
# Copyright (c) 2010 Branden Schneider # Copyright (c) 2010 Branden Schneider
# Copyright (c) 2010-2016 Claudio Kuenzler # Copyright (c) 2010-2019 Claudio Kuenzler
# Copyright (c) 2010 Samir Ibradzic # Copyright (c) 2010 Samir Ibradzic
# Copyright (c) 2010 Aaron Rogers # Copyright (c) 2010 Aaron Rogers
# Copyright (c) 2011 Ludovic Hutin # Copyright (c) 2011 Ludovic Hutin
@@ -38,6 +38,7 @@
# Copyright (c) 2015 Andreas Gottwald # Copyright (c) 2015 Andreas Gottwald
# Copyright (c) 2015 Stanislav German-Evtushenko # Copyright (c) 2015 Stanislav German-Evtushenko
# Copyright (c) 2015 Stefan Roos # Copyright (c) 2015 Stefan Roos
# Copyright (c) 2018 Peter Newman
# #
# The VMware 4.1 CIM API is documented here: # The VMware 4.1 CIM API is documented here:
# http://www.vmware.com/support/developer/cim-sdk/4.1/smash/cim_smash_410_prog.pdf # http://www.vmware.com/support/developer/cim-sdk/4.1/smash/cim_smash_410_prog.pdf
@@ -46,8 +47,8 @@
# The VMware 5.x CIM API is documented here: # The VMware 5.x CIM API is documented here:
# http://pubs.vmware.com/vsphere-50/index.jsp?nav=/5_1_1 # http://pubs.vmware.com/vsphere-50/index.jsp?nav=/5_1_1
# #
# This Nagios plugin is maintained here: # This monitoring plugin is maintained and documented here:
# http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.php # https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
# #
#@--------------------------------------------------- #@---------------------------------------------------
#@ History #@ History
@@ -243,7 +244,28 @@
#@ Author : Claudio Kuenzler (www.claudiokuenzler.com) #@ Author : Claudio Kuenzler (www.claudiokuenzler.com)
#@ Reason : Added support for pywbem 0.9.x (and upcoming releases) #@ Reason : Added support for pywbem 0.9.x (and upcoming releases)
#@--------------------------------------------------- #@---------------------------------------------------
#@ Date : 20170905
#@ Author : Claudio Kuenzler (www.claudiokuenzler.com)
#@ Reason : Added option to ignore LCD/Display related elements (--no-lcd)
#@---------------------------------------------------
#@ Date : 20180329
#@ Author : Claudio Kuenzler (www.claudiokuenzler.com)
#@ Reason : Try to use internal pywbem function to determine version
#@---------------------------------------------------
#@ Date : 20180411
#@ Author : Peter Newman
#@ Reason : Throw an unknown if we can't fetch the data for some reason
#@---------------------------------------------------
#@ Date : 20181001
#@ Author : Claudio Kuenzler
#@ Reason : python3 compatibility
#@---------------------------------------------------
#@ Date : 20190510
#@ Author : Claudio Kuenzler
#@ Reason : Allow regular expressions from ignore list (-r)
#@---------------------------------------------------
from __future__ import print_function
import sys import sys
import time import time
import pywbem import pywbem
@@ -251,7 +273,7 @@ import re
import pkg_resources import pkg_resources
from optparse import OptionParser,OptionGroup from optparse import OptionParser,OptionGroup
version = '20161013' version = '20190510'
NS = 'root/cimv2' NS = 'root/cimv2'
hosturl = '' hosturl = ''
@@ -338,6 +360,8 @@ timeout = 0
# elements to ignore (full SEL, broken BIOS, etc) # elements to ignore (full SEL, broken BIOS, etc)
ignore_list=[] ignore_list=[]
regex_ignore_list=[]
regex=False
# urlise model and tag numbers (currently only Dell supported, but the code does the right thing for other vendors) # urlise model and tag numbers (currently only Dell supported, but the code does the right thing for other vendors)
urlise_country='' urlise_country=''
@@ -348,6 +372,7 @@ get_volts = True
get_current = True get_current = True
get_temp = True get_temp = True
get_fan = True get_fan = True
get_lcd = True
# define exit codes # define exit codes
ExitOK = 0 ExitOK = 0
@@ -467,14 +492,14 @@ def urlised_serialnumber(vendor,country,SerialNumber):
def verboseoutput(message) : def verboseoutput(message) :
if verbose: if verbose:
print "%s %s" % (time.strftime("%Y%m%d %H:%M:%S"), message) print(time.strftime("%Y%m%d %H:%M:%S"), message)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
def getopts() : def getopts() :
global hosturl,cimport,user,password,vendor,verbose,perfdata,urlise_country,timeout,ignore_list,get_power,get_volts,get_current,get_temp,get_fan global hosturl,cimport,user,password,vendor,verbose,perfdata,urlise_country,timeout,ignore_list,regex,get_power,get_volts,get_current,get_temp,get_fan,get_lcd
usage = "usage: %prog -H hostname -U username -P password [-C port -V system -v -p -I XX]\n" \ usage = "usage: %prog -H hostname -U username -P password [-C port -V vendor -v -p -I XX -i list,list -r]\n" \
"example: %prog -H my-shiny-new-vmware-server -U root -P fakepassword -C 5989 -V auto -I uk\n\n" \ "example: %prog -H hostname -U root -P password -C 5989 -V auto -I uk\n\n" \
"or, verbosely:\n\n" \ "or, verbosely:\n\n" \
"usage: %prog --host=hostname --user=username --pass=password [--cimport=port --vendor=system --verbose --perfdata --html=XX]\n" "usage: %prog --host=hostname --user=username --pass=password [--cimport=port --vendor=system --verbose --perfdata --html=XX]\n"
@@ -500,6 +525,8 @@ def getopts() :
help="timeout in seconds - no effect on Windows (default = no timeout)") help="timeout in seconds - no effect on Windows (default = no timeout)")
group2.add_option("-i", "--ignore", action="store", type="string", dest="ignore", default="", \ group2.add_option("-i", "--ignore", action="store", type="string", dest="ignore", default="", \
help="comma-separated list of elements to ignore") help="comma-separated list of elements to ignore")
group2.add_option("-r", "--regex", action="store_true", dest="regex", default=False, \
help="allow regular expression lookup of ignore list")
group2.add_option("--no-power", action="store_false", dest="get_power", default=True, \ group2.add_option("--no-power", action="store_false", dest="get_power", default=True, \
help="don't collect power performance data") help="don't collect power performance data")
group2.add_option("--no-volts", action="store_false", dest="get_volts", default=True, \ group2.add_option("--no-volts", action="store_false", dest="get_volts", default=True, \
@@ -510,20 +537,22 @@ def getopts() :
help="don't collect temperature performance data") help="don't collect temperature performance data")
group2.add_option("--no-fan", action="store_false", dest="get_fan", default=True, \ group2.add_option("--no-fan", action="store_false", dest="get_fan", default=True, \
help="don't collect fan performance data") help="don't collect fan performance data")
group2.add_option("--no-lcd", action="store_false", dest="get_lcd", default=True, \
help="don't collect lcd/front display status")
parser.add_option_group(group1) parser.add_option_group(group1)
parser.add_option_group(group2) parser.add_option_group(group2)
# check input arguments # check input arguments
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "no parameters specified\n" print("no parameters specified\n")
parser.print_help() parser.print_help()
sys.exit(-1) sys.exit(-1)
# if first argument starts with 'https://' we have old-style parameters, so handle in old way # if first argument starts with 'https://' we have old-style parameters, so handle in old way
if re.match("https://",sys.argv[1]): if re.match("https://",sys.argv[1]):
# check input arguments # check input arguments
if len(sys.argv) < 5: if len(sys.argv) < 5:
print "too few parameters\n" print("too few parameters\n")
parser.print_help() parser.print_help()
sys.exit(-1) sys.exit(-1)
if len(sys.argv) > 5 : if len(sys.argv) > 5 :
@@ -541,7 +570,7 @@ def getopts() :
mandatories = ['host', 'user', 'password'] mandatories = ['host', 'user', 'password']
for m in mandatories: for m in mandatories:
if not options.__dict__[m]: if not options.__dict__[m]:
print "mandatory parameter '--" + m + "' is missing\n" print("mandatory parameter '--" + m + "' is missing\n")
parser.print_help() parser.print_help()
sys.exit(-1) sys.exit(-1)
@@ -562,11 +591,13 @@ def getopts() :
urlise_country=options.urlise_country.lower() urlise_country=options.urlise_country.lower()
timeout=options.timeout timeout=options.timeout
ignore_list=options.ignore.split(',') ignore_list=options.ignore.split(',')
regex=options.regex
get_power=options.get_power get_power=options.get_power
get_volts=options.get_volts get_volts=options.get_volts
get_current=options.get_current get_current=options.get_current
get_temp=options.get_temp get_temp=options.get_temp
get_fan=options.get_fan get_fan=options.get_fan
get_lcd=options.get_lcd
# if user or password starts with 'file:', use the first string in file as user, second as password # if user or password starts with 'file:', use the first string in file as user, second as password
if (re.match('^file:', user) or re.match('^file:', password)): if (re.match('^file:', user) or re.match('^file:', password)):
@@ -595,25 +626,39 @@ if os_platform != "win32":
on_windows = False on_windows = False
import signal import signal
def handler(signum, frame): def handler(signum, frame):
print 'UNKNOWN: Execution time too long!' print('UNKNOWN: Execution time too long!')
sys.exit(ExitUnknown) sys.exit(ExitUnknown)
if cimport: if cimport:
verboseoutput("Using manually defined CIM port "+cimport) verboseoutput("Using manually defined CIM port "+cimport)
hosturl += ':'+cimport hosturl += ':'+cimport
# Append lcd related elements to ignore list if --no-lcd was used
verboseoutput("LCD Status: %s" % get_lcd)
if not get_lcd:
ignore_list.append("System Board 1 LCD Cable Pres 0: Connected")
ignore_list.append("System Board 1 VGA Cable Pres 0: Connected")
ignore_list.append("Front Panel Board 1 FP LCD Cable 0: Connected")
ignore_list.append("Front Panel Board 1 FP LCD Cable 0: Config Error")
# connection to host # connection to host
verboseoutput("Connection to "+hosturl) verboseoutput("Connection to "+hosturl)
# pywbem 0.7.0 handling is special, some patched 0.7.0 installations work differently # pywbem 0.7.0 handling is special, some patched 0.7.0 installations work differently
try:
pywbemversion = pywbem.__version__
except:
pywbemversion = pkg_resources.get_distribution("pywbem").version pywbemversion = pkg_resources.get_distribution("pywbem").version
else:
pywbemversion = pywbem.__version__
verboseoutput("Found pywbem version "+pywbemversion) verboseoutput("Found pywbem version "+pywbemversion)
if '0.7.' in pywbemversion: if '0.7.' in pywbemversion:
try: try:
conntest = pywbem.WBEMConnection(hosturl, (user,password)) conntest = pywbem.WBEMConnection(hosturl, (user,password))
c = conntest.EnumerateInstances('CIM_Card') c = conntest.EnumerateInstances('CIM_Card')
except: except:
#raise #raise
verboseoutput("Connection error, disable SSL certification verification (probably patched pywbem)") verboseoutput("Connection error, disable SSL certificate verification (probably patched pywbem)")
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), no_verification=True) wbemclient = pywbem.WBEMConnection(hosturl, (user,password), no_verification=True)
else: else:
verboseoutput("Connection worked") verboseoutput("Connection worked")
@@ -639,16 +684,19 @@ ExitMsg = ""
if vendor=='auto': if vendor=='auto':
try: try:
c=wbemclient.EnumerateInstances('CIM_Chassis') c=wbemclient.EnumerateInstances('CIM_Chassis')
except pywbem.cim_operations.CIMError,args: except pywbem.cim_operations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ): if ( args[1].find('Socket error') >= 0 ):
print "UNKNOWN: %s" %args print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown)
elif ( args[1].find('ThreadPool --- Failed to enqueue request') >= 0 ):
print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
else: else:
verboseoutput("Unknown CIM Error: %s" % args) verboseoutput("Unknown CIM Error: %s" % args)
except pywbem.cim_http.AuthError,arg: except pywbem.cim_http.AuthError as arg:
verboseoutput("Global exit set to UNKNOWN") verboseoutput("Global exit set to UNKNOWN")
GlobalStatus = ExitUnknown GlobalStatus = ExitUnknown
print "UNKNOWN: Authentication Error" print("UNKNOWN: Authentication Error")
sys.exit (GlobalStatus) sys.exit (GlobalStatus)
else: else:
man=c[0][u'Manufacturer'] man=c[0][u'Manufacturer']
@@ -667,16 +715,19 @@ for classe in ClassesToCheck :
verboseoutput("Check classe "+classe) verboseoutput("Check classe "+classe)
try: try:
instance_list = wbemclient.EnumerateInstances(classe) instance_list = wbemclient.EnumerateInstances(classe)
except pywbem.cim_operations.CIMError,args: except pywbem.cim_operations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ): if ( args[1].find('Socket error') >= 0 ):
print "UNKNOWN: %s" %args print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown)
elif ( args[1].find('ThreadPool --- Failed to enqueue request') >= 0 ):
print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
else: else:
verboseoutput("Unknown CIM Error: %s" % args) verboseoutput("Unknown CIM Error: %s" % args)
except pywbem.cim_http.AuthError,arg: except pywbem.cim_http.AuthError as arg:
verboseoutput("Global exit set to UNKNOWN") verboseoutput("Global exit set to UNKNOWN")
GlobalStatus = ExitUnknown GlobalStatus = ExitUnknown
print "UNKNOWN: Authentication Error" print("UNKNOWN: Authentication Error")
sys.exit (GlobalStatus) sys.exit (GlobalStatus)
else: else:
# GlobalStatus = ExitOK #ARR # GlobalStatus = ExitOK #ARR
@@ -688,7 +739,13 @@ for classe in ClassesToCheck :
verboseoutput(" Element Name = "+elementName) verboseoutput(" Element Name = "+elementName)
# Ignore element if we don't want it # Ignore element if we don't want it
if elementName in ignore_list : if (regex == True) and (len(ignore_list) > 0) :
for ignore in ignore_list :
if re.search(ignore, elementName, re.IGNORECASE) :
verboseoutput(" (ignored through regex)")
regex_ignore_list.append(elementName)
if (elementName in ignore_list) or (elementName in regex_ignore_list) :
verboseoutput(" (ignored)") verboseoutput(" (ignored)")
continue continue
@@ -788,7 +845,6 @@ for classe in ClassesToCheck :
verboseoutput(" Family = %d" % instance['Family']) verboseoutput(" Family = %d" % instance['Family'])
verboseoutput(" CurrentClockSpeed = %dMHz" % instance['CurrentClockSpeed']) verboseoutput(" CurrentClockSpeed = %dMHz" % instance['CurrentClockSpeed'])
# HP Check # HP Check
if vendor == "hp" : if vendor == "hp" :
if instance['HealthState'] is not None : if instance['HealthState'] is not None :
@@ -804,11 +860,11 @@ for classe in ClassesToCheck :
30 : ExitCritical, # Non-recoverable Error 30 : ExitCritical, # Non-recoverable Error
}[elementStatus] }[elementStatus]
if (interpretStatus == ExitCritical) : if (interpretStatus == ExitCritical) :
verboseoutput("GLobal exit set to CRITICAL") verboseoutput("Global exit set to CRITICAL")
GlobalStatus = ExitCritical GlobalStatus = ExitCritical
ExitMsg += " CRITICAL : %s " % elementNameValue ExitMsg += " CRITICAL : %s " % elementNameValue
if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) : if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) :
verboseoutput("GLobal exit set to WARNING") verboseoutput("Global exit set to WARNING")
GlobalStatus = ExitWarning GlobalStatus = ExitWarning
ExitMsg += " WARNING : %s " % elementNameValue ExitMsg += " WARNING : %s " % elementNameValue
# Added the following for when GlobalStatus is ExitCritical and a warning is detected # Added the following for when GlobalStatus is ExitCritical and a warning is detected
@@ -825,8 +881,6 @@ for classe in ClassesToCheck :
elif (vendor == "dell" or vendor == "intel" or vendor == "ibm" or vendor=="unknown") : elif (vendor == "dell" or vendor == "intel" or vendor == "ibm" or vendor=="unknown") :
# Added 20121027 As long as Dell doesnt correct these CIM elements return code we have to ignore it # Added 20121027 As long as Dell doesnt correct these CIM elements return code we have to ignore it
ignore_list.append("System Board 1 Riser Config Err 0: Connected") ignore_list.append("System Board 1 Riser Config Err 0: Connected")
ignore_list.append("System Board 1 LCD Cable Pres 0: Connected")
ignore_list.append("System Board 1 VGA Cable Pres 0: Connected")
ignore_list.append("Add-in Card 4 PEM Presence 0: Connected") ignore_list.append("Add-in Card 4 PEM Presence 0: Connected")
if instance['OperationalStatus'] is not None : if instance['OperationalStatus'] is not None :
elementStatus = instance['OperationalStatus'][0] elementStatus = instance['OperationalStatus'][0]
@@ -859,7 +913,7 @@ for classe in ClassesToCheck :
GlobalStatus = ExitCritical GlobalStatus = ExitCritical
ExitMsg += " CRITICAL : %s " % elementNameValue ExitMsg += " CRITICAL : %s " % elementNameValue
if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) : if (interpretStatus == ExitWarning and GlobalStatus != ExitCritical) :
verboseoutput("GLobal exit set to WARNING") verboseoutput("Global exit set to WARNING")
GlobalStatus = ExitWarning GlobalStatus = ExitWarning
ExitMsg += " WARNING : %s " % elementNameValue ExitMsg += " WARNING : %s " % elementNameValue
# Added same logic as in 20100702 here, otherwise Dell servers would return UNKNOWN instead of OK # Added same logic as in 20100702 here, otherwise Dell servers would return UNKNOWN instead of OK
@@ -903,12 +957,12 @@ if perf == '|':
perf = '' perf = ''
if GlobalStatus == ExitOK : if GlobalStatus == ExitOK :
print "OK - Server: %s %s %s%s" % (server_info, SerialNumber, bios_info, perf) print("OK - Server: %s %s %s%s" % (server_info, SerialNumber, bios_info, perf))
elif GlobalStatus == ExitUnknown : elif GlobalStatus == ExitUnknown :
print "UNKNOWN: %s" % (ExitMsg) #ARR print("UNKNOWN: %s" % (ExitMsg)) #ARR
else: else:
print "%s- Server: %s %s %s%s" % (ExitMsg, server_info, SerialNumber, bios_info, perf) print("%s - Server: %s %s %s%s" % (ExitMsg, server_info, SerialNumber, bios_info, perf))
sys.exit (GlobalStatus) sys.exit (GlobalStatus)