|
15 | 15 | # GNU General Public License for more details. |
16 | 16 | # |
17 | 17 | # You should have received a copy of the GNU General Public License |
18 | | -# along with this program; if not, write to the Free Software |
19 | | -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
20 | | -# 02110-1301, USA. |
| 18 | +# along with this program; if not, see <https://www.gnu.org/licenses/>. |
21 | 19 | # |
22 | 20 | # Pre-req : pywbem |
23 | 21 | # |
24 | 22 | # Copyright (c) 2008 David Ligeret |
25 | 23 | # Copyright (c) 2009 Joshua Daniel Franklin |
26 | 24 | # Copyright (c) 2010 Branden Schneider |
27 | | -# Copyright (c) 2010-2019 Claudio Kuenzler |
| 25 | +# Copyright (c) 2010-2020 Claudio Kuenzler |
28 | 26 | # Copyright (c) 2010 Samir Ibradzic |
29 | 27 | # Copyright (c) 2010 Aaron Rogers |
30 | 28 | # Copyright (c) 2011 Ludovic Hutin |
|
39 | 37 | # Copyright (c) 2015 Stanislav German-Evtushenko |
40 | 38 | # Copyright (c) 2015 Stefan Roos |
41 | 39 | # Copyright (c) 2018 Peter Newman |
42 | | -# Copyright (c) 2019 Luca Berra |
| 40 | +# Copyright (c) 2020 Luca Berra |
43 | 41 | # |
44 | 42 | # The VMware 4.1 CIM API is documented here: |
45 | 43 | # http://www.vmware.com/support/developer/cim-sdk/4.1/smash/cim_smash_410_prog.pdf |
46 | 44 | # http://www.vmware.com/support/developer/cim-sdk/smash/u2/ga/apirefdoc/ |
47 | 45 | # |
48 | | -# The VMware 5.x CIM API is documented here: |
49 | | -# http://pubs.vmware.com/vsphere-50/index.jsp?nav=/5_1_1 |
| 46 | +# The VMware 5.5 and above CIM API is documented here: |
| 47 | +# https://code.vmware.com/apis/207/cim |
50 | 48 | # |
51 | 49 | # This monitoring plugin is maintained and documented here: |
52 | 50 | # https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php |
|
269 | 267 | #@ Author : Phil Randal (phil.randal@gmail.com) |
270 | 268 | #@ Reason : Fix lookup of warranty info for Dell (again) |
271 | 269 | #@--------------------------------------------------- |
272 | | -#@ Date : 20191115 |
| 270 | +#@ Date : 20200605 |
273 | 271 | #@ Author : Luca Berra |
274 | 272 | #@ Reason : Add option to ignore chassis intrusion (Supermicro) |
| 273 | +#@--------------------------------------------------- |
| 274 | +#@ Date : 20200605 |
| 275 | +#@ Author : Claudio Kuenzler |
| 276 | +#@ Reason : Add parameter (-S) for custom SSL/TLS protocol version |
| 277 | +#@--------------------------------------------------- |
275 | 278 |
|
276 | 279 | from __future__ import print_function |
277 | 280 | import sys |
|
281 | 284 | import pkg_resources |
282 | 285 | from optparse import OptionParser,OptionGroup |
283 | 286 |
|
284 | | -version = '20191115' |
| 287 | +version = '20200605' |
285 | 288 |
|
286 | 289 | NS = 'root/cimv2' |
287 | 290 | hosturl = '' |
@@ -506,22 +509,23 @@ def verboseoutput(message) : |
506 | 509 | # ---------------------------------------------------------------------- |
507 | 510 |
|
508 | 511 | def getopts() : |
509 | | - 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,get_intrusion |
510 | | - usage = "usage: %prog -H hostname -U username -P password [-C port -V vendor -v -p -I XX -i list,list -r]\n" \ |
| 512 | + global hosturl,hostname,cimport,sslproto,user,password,vendor,verbose,perfdata,urlise_country,timeout,ignore_list,regex,get_power,get_volts,get_current,get_temp,get_fan,get_lcd,get_intrusion |
| 513 | + usage = "usage: %prog -H hostname -U username -P password [-C port -S proto -V vendor -v -p -I XX -i list,list -r]\n" \ |
511 | 514 | "example: %prog -H hostname -U root -P password -C 5989 -V auto -I uk\n\n" \ |
512 | 515 | "or, verbosely:\n\n" \ |
513 | | - "usage: %prog --host=hostname --user=username --pass=password [--cimport=port --vendor=system --verbose --perfdata --html=XX]\n" |
| 516 | + "usage: %prog --host=hostname --user=username --pass=password [--cimport=port --sslproto=version --vendor=system --verbose --perfdata --html=XX]\n" |
514 | 517 |
|
515 | 518 | parser = OptionParser(usage=usage, version="%prog "+version) |
516 | 519 | group1 = OptionGroup(parser, 'Mandatory parameters') |
517 | 520 | group2 = OptionGroup(parser, 'Optional parameters') |
518 | 521 |
|
519 | | - group1.add_option("-H", "--host", dest="host", help="report on HOST", metavar="HOST") |
| 522 | + group1.add_option("-H", "--host", dest="host", help="connect to HOST", metavar="HOST") |
520 | 523 | group1.add_option("-U", "--user", dest="user", help="user to connect as", metavar="USER") |
521 | 524 | group1.add_option("-P", "--pass", dest="password", \ |
522 | 525 | help="password, if password matches file:<path>, first line of given file will be used as password", metavar="PASS") |
523 | 526 |
|
524 | 527 | group2.add_option("-C", "--cimport", dest="cimport", help="CIM port (default 5989)", metavar="CIMPORT") |
| 528 | + group2.add_option("-S", "--sslproto", dest="sslproto", help="SSL/TLS protocol version to overwrite system default: SSLv2, SSLv3, TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3", metavar="SSLPROTO") |
525 | 529 | group2.add_option("-V", "--vendor", dest="vendor", help="Vendor code: auto, dell, hp, ibm, intel, or unknown (default)", \ |
526 | 530 | metavar="VENDOR", type='choice', choices=['auto','dell','hp','ibm','intel','unknown'],default="unknown") |
527 | 531 | group2.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, \ |
@@ -596,6 +600,7 @@ def getopts() : |
596 | 600 | user=options.user |
597 | 601 | password=options.password |
598 | 602 | cimport=options.cimport |
| 603 | + sslproto=options.sslproto |
599 | 604 | vendor=options.vendor.lower() |
600 | 605 | verbose=options.verbose |
601 | 606 | perfdata=options.perfdata |
@@ -641,10 +646,30 @@ def handler(signum, frame): |
641 | 646 | print('UNKNOWN: Execution time too long!') |
642 | 647 | sys.exit(ExitUnknown) |
643 | 648 |
|
| 649 | +# Use non-default CIM port |
644 | 650 | if cimport: |
645 | 651 | verboseoutput("Using manually defined CIM port "+cimport) |
646 | 652 | hosturl += ':'+cimport |
647 | | - |
| 653 | + |
| 654 | +# Use non-default SSL protocol version |
| 655 | +if sslproto: |
| 656 | + verboseoutput("Using non-default SSL protocol: "+sslproto) |
| 657 | + allowed_protos = ["SSLv2", "SSLv3", "TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3"] |
| 658 | + if any(proto.lower() == sslproto.lower() for proto in allowed_protos): |
| 659 | + import os |
| 660 | + sslconfpath = '/tmp/'+hostname+'_openssl.conf' |
| 661 | + verboseoutput("Creating OpenSSL config file: "+sslconfpath) |
| 662 | + try: |
| 663 | + with open(sslconfpath, 'w') as config_file: |
| 664 | + config_file.write("openssl_conf = openssl_init\n[openssl_init]\nssl_conf = ssl_configuration\n[ssl_configuration]\nsystem_default = tls_system_default\n[tls_system_default]\nMinProtocol = "+sslproto+"\n") |
| 665 | + except Exception as e: |
| 666 | + print('CRITICAL: An error occured while trying to write ssl config file: %s (%s)' % (sslconfpath, e)) |
| 667 | + sys.exit(ExitCritical) |
| 668 | + os.environ["OPENSSL_CONF"] = sslconfpath |
| 669 | + else: |
| 670 | + print('CRITICAL: Invalid SSL protocol version given!') |
| 671 | + sys.exit(ExitCritical) |
| 672 | + |
648 | 673 | # Append lcd related elements to ignore list if --no-lcd was used |
649 | 674 | verboseoutput("LCD Status: %s" % get_lcd) |
650 | 675 | if not get_lcd: |
@@ -717,6 +742,10 @@ def handler(signum, frame): |
717 | 742 | sys.exit (ExitUnknown) |
718 | 743 | else: |
719 | 744 | verboseoutput("Unknown CIM Error: %s" % args) |
| 745 | + except pywbem._exceptions.ConnectionError as args: |
| 746 | + GlobalStatus = ExitUnknown |
| 747 | + print("UNKNOWN: {}".format(args)) |
| 748 | + sys.exit (GlobalStatus) |
720 | 749 | except pywbem.cim_http.AuthError as arg: |
721 | 750 | verboseoutput("Global exit set to UNKNOWN") |
722 | 751 | GlobalStatus = ExitUnknown |
@@ -748,6 +777,10 @@ def handler(signum, frame): |
748 | 777 | sys.exit (ExitUnknown) |
749 | 778 | else: |
750 | 779 | verboseoutput("Unknown CIM Error: %s" % args) |
| 780 | + except pywbem._exceptions.ConnectionError as args: |
| 781 | + GlobalStatus = ExitUnknown |
| 782 | + print("UNKNOWN: {}".format(args)) |
| 783 | + sys.exit (GlobalStatus) |
751 | 784 | except pywbem.cim_http.AuthError as arg: |
752 | 785 | verboseoutput("Global exit set to UNKNOWN") |
753 | 786 | GlobalStatus = ExitUnknown |
|
0 commit comments