mirror of
https://github.com/Napsty/check_esxi_hardware.git
synced 2024-11-24 19:33:48 +01:00
Allow regular expressions from ignore list (-r)
This commit is contained in:
parent
df56d7373d
commit
8bcf7309d9
@ -24,7 +24,7 @@
|
||||
# Copyright (c) 2008 David Ligeret
|
||||
# Copyright (c) 2009 Joshua Daniel Franklin
|
||||
# Copyright (c) 2010 Branden Schneider
|
||||
# Copyright (c) 2010-2018 Claudio Kuenzler
|
||||
# Copyright (c) 2010-2019 Claudio Kuenzler
|
||||
# Copyright (c) 2010 Samir Ibradzic
|
||||
# Copyright (c) 2010 Aaron Rogers
|
||||
# Copyright (c) 2011 Ludovic Hutin
|
||||
@ -47,8 +47,8 @@
|
||||
# The VMware 5.x CIM API is documented here:
|
||||
# http://pubs.vmware.com/vsphere-50/index.jsp?nav=/5_1_1
|
||||
#
|
||||
# This Nagios plugin is maintained here:
|
||||
# http://www.claudiokuenzler.com/nagios-plugins/check_esxi_hardware.php
|
||||
# This Nagios plugin is maintained and documented here:
|
||||
# http://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
|
||||
#
|
||||
#@---------------------------------------------------
|
||||
#@ History
|
||||
@ -260,6 +260,10 @@
|
||||
#@ Author : Claudio Kuenzler
|
||||
#@ Reason : python3 compatibility
|
||||
#@---------------------------------------------------
|
||||
#@ Date : 20190503
|
||||
#@ Author : Claudio Kuenzler
|
||||
#@ Reason : Allow regular expressions from ignore list (-r)
|
||||
#@---------------------------------------------------
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
@ -269,7 +273,7 @@ import re
|
||||
import pkg_resources
|
||||
from optparse import OptionParser,OptionGroup
|
||||
|
||||
version = '20181001'
|
||||
version = '20190503'
|
||||
|
||||
NS = 'root/cimv2'
|
||||
hosturl = ''
|
||||
@ -356,6 +360,8 @@ timeout = 0
|
||||
|
||||
# elements to ignore (full SEL, broken BIOS, etc)
|
||||
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_country=''
|
||||
@ -491,9 +497,9 @@ def verboseoutput(message) :
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
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,get_lcd
|
||||
usage = "usage: %prog -H hostname -U username -P password [-C port -V system -v -p -I XX]\n" \
|
||||
"example: %prog -H my-shiny-new-vmware-server -U root -P fakepassword -C 5989 -V auto -I uk\n\n" \
|
||||
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 vendor -v -p -I XX -i list,list -r]\n" \
|
||||
"example: %prog -H hostname -U root -P password -C 5989 -V auto -I uk\n\n" \
|
||||
"or, verbosely:\n\n" \
|
||||
"usage: %prog --host=hostname --user=username --pass=password [--cimport=port --vendor=system --verbose --perfdata --html=XX]\n"
|
||||
|
||||
@ -519,6 +525,8 @@ def getopts() :
|
||||
help="timeout in seconds - no effect on Windows (default = no timeout)")
|
||||
group2.add_option("-i", "--ignore", action="store", type="string", dest="ignore", default="", \
|
||||
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, \
|
||||
help="don't collect power performance data")
|
||||
group2.add_option("--no-volts", action="store_false", dest="get_volts", default=True, \
|
||||
@ -583,6 +591,7 @@ def getopts() :
|
||||
urlise_country=options.urlise_country.lower()
|
||||
timeout=options.timeout
|
||||
ignore_list=options.ignore.split(',')
|
||||
regex=options.regex
|
||||
get_power=options.get_power
|
||||
get_volts=options.get_volts
|
||||
get_current=options.get_current
|
||||
@ -649,7 +658,7 @@ if '0.7.' in pywbemversion:
|
||||
c = conntest.EnumerateInstances('CIM_Card')
|
||||
except:
|
||||
#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)
|
||||
else:
|
||||
verboseoutput("Connection worked")
|
||||
@ -730,7 +739,13 @@ for classe in ClassesToCheck :
|
||||
verboseoutput(" Element Name = "+elementName)
|
||||
|
||||
# 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)")
|
||||
continue
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user