1
0
mirror of https://github.com/Napsty/check_esxi_hardware.git synced 2025-04-19 14:03:40 +02:00

Compare commits

..

No commits in common. "master" and "20220708" have entirely different histories.

4 changed files with 224 additions and 66 deletions

View File

@ -15,8 +15,8 @@ I confirm, I have cleared the server's local IPMI cache (`localcli hardware ipmi
**Describe the bug** **Describe the bug**
A clear and concise description of what the bug is. A clear and concise description of what the bug is.
**Show the full plugin output, including the command with -v parameter** **Show the full plugin output, including the command with -V parameter**
Run the plugin with `-v` parameter and show the full output (including command) here. Obviously obfuscate credentials. Run the plugin with `-V` parameter and show the full output (including command) here. Obviously obfuscate credentials.
**Expected behavior** **Expected behavior**
A clear and concise description of what you expected to happen. A clear and concise description of what you expected to happen.

77
.github/workflows/python2check.yml vendored Normal file
View File

@ -0,0 +1,77 @@
# @file python2check.yml
---
name: Python2 check
# Trigger the workflow on push or pull request
on: [push, pull_request]
jobs:
python2-pywbem08:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '2.7'
- name: Install pywbem from apt
run: |
sudo apt-get install -qq -yy python-pywbem
- name: Set environment PYTHONPATH
run: |
export PYTHONPATH=/opt/hostedtoolcache/Python
- name: Launch script with --help
run: |
./check_esxi_hardware.py --help
# Jobs with PIP installations are currently disabled.
# python2-pywbem09:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '2.7'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python-pip
# pip install pywbem==0.9.1
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python2-pywbem012:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '2.7'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python-pip
# pip install pywbem==0.12.6
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python2-pywbem014:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '2.7'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python-pip
# pip install pywbem==0.14.6
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help

View File

@ -6,16 +6,109 @@ name: Python3 check
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
python3-pywbem-latest: simple-output:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - name: Simple hello world
- name: Install latest pywbem from pip run: echo "Hello World"
run: | # python3-pywbem-latest:
sudo apt-get install -qq -yy python3 python3-pip # runs-on: ubuntu-latest
pip3 install pywbem # steps:
- name: Verify python sys.path # - uses: actions/checkout@v1
run: (echo "import sys"; echo "print(', '.join(sys.path))") | python3 # - uses: actions/setup-python@v1
- name: Launch script with --help # with:
run: | # python-version: '3.8'
./check_esxi_hardware.py --help # - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python3-pip
# pip3 install pywbem
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python/3.8.0/x64/lib/python3.8/site-packages
# - name: Verify python sys.path
# run: (echo "import sys"; echo "print(', '.join(sys.path))") | python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python3-pywbem-08:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.x'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python3-pip
# pip3 install pywbem==0.8.4
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python3-pywbem-012:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.x'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python3-pip
# pip3 install pywbem==0.12.6
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python3-pywbem-013:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.x'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python3-pip
# pip3 install pywbem==0.13.1
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# python3-pywbem-014:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.x'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python3-pip
# pip3 install pywbem==0.14.6
# - name: Set environment PYTHONPATH
# run: |
# export PYTHONPATH=/opt/hostedtoolcache/Python
# - name: Launch script with --help
# run: |
# ./check_esxi_hardware.py --help
# find-pywbem:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.x'
# - name: Install latest pywbem from pip
# run: |
# sudo apt-get install -qq -yy python-pip
# pip install pywbem
# - name: Find pywbem module
# run: |
# find / -name 'pywbem-*'

View File

@ -1,4 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# #
# Script for checking global health of host running VMware ESX/ESXi # Script for checking global health of host running VMware ESX/ESXi
@ -22,7 +22,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-2025 Claudio Kuenzler # Copyright (c) 2010-2022 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
@ -40,11 +40,12 @@
# Copyright (c) 2020 Luca Berra # Copyright (c) 2020 Luca Berra
# Copyright (c) 2022 Marco Markgraf # Copyright (c) 2022 Marco Markgraf
# #
# The VMware CIM API is documented here (as of October 2024): # The VMware 4.1 CIM API is documented here:
# https://docs.vmware.com/en/VMware-vSphere/7.0/vsphere-cim-smash-server-management-api-programming-guide/GUID-2725D01E-AE02-4EF2-9E98-5AB82AA0349A.html # http://www.vmware.com/support/developer/cim-sdk/4.1/smash/cim_smash_410_prog.pdf
# http://www.vmware.com/support/developer/cim-sdk/smash/u2/ga/apirefdoc/
# The CIM classes are documented here (as of October 2024): #
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/27c1c014-7315-4d6b-8e6b-292130a79b3c/36aca268-99fa-4916-b993-a077de55cbf1/CIM_API_Reference/index.html # The VMware 5.5 and above CIM API is documented here:
# https://code.vmware.com/apis/207/cim
# #
# This monitoring plugin is maintained and documented here: # This monitoring plugin is maintained and documented here:
# https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php # https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
@ -288,31 +289,17 @@
#@ Author : Marco Markgraf #@ Author : Marco Markgraf
#@ Reason : Added JSON-output (Zabbix needs it) #@ Reason : Added JSON-output (Zabbix needs it)
#@--------------------------------------------------- #@---------------------------------------------------
#@ Date : 20221230
#@ Author : Claudio Kuenzler
#@ Reason : Fix bug when missing S/N (issue #68)
#@---------------------------------------------------
#@ Date : 20241129
#@ Author : Claudio Kuenzler
#@ Reason : Fix pkg_resources deprecation warning
# Remove python2 compatibility
# Remove pywbem 0.7.0 compatibility
#@---------------------------------------------------
#@ Date : 20250221
#@ Author : Claudio Kuenzler
#@ Reason : Update to newer pywbem exception call, catch HTTPError
#@ Attn : Requires 'packaging' Python module from now on!
#@---------------------------------------------------
from __future__ import print_function
import sys import sys
import time import time
import pywbem import pywbem
import re import re
import pkg_resources
import json import json
from optparse import OptionParser,OptionGroup from optparse import OptionParser,OptionGroup
from packaging.version import Version
version = '20250221' version = '20220708'
NS = 'root/cimv2' NS = 'root/cimv2'
hosturl = '' hosturl = ''
@ -738,22 +725,30 @@ if not get_intrusion:
ignore_list.append("System Chassis 1 Chassis Intru: Unknown") ignore_list.append("System Chassis 1 Chassis Intru: Unknown")
# connection to host # connection to host
pywbemversion = pywbem.__version__
verboseoutput("Found pywbem version "+pywbemversion)
verboseoutput("Connection to "+hosturl) verboseoutput("Connection to "+hosturl)
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), NS, no_verification=True) # pywbem 0.7.0 handling is special, some patched 0.7.0 installations work differently
try:
# Backward compatibility for older pywbem exceptions, big thanks to Claire M.! pywbemversion = pywbem.__version__
if Version(pywbemversion) >= Version("1.0.0"): except:
verboseoutput("pywbem is 1.0.0 or newer") pywbemversion = pkg_resources.get_distribution("pywbem").version
import pywbem._cim_operations as PywbemCimOperations
import pywbem._cim_http as PywbemCimHttp
import pywbem._exceptions as PywbemExceptions
else: else:
verboseoutput("pywbem is older than 1.0.0") pywbemversion = pywbem.__version__
import pywbem.cim_operations as PywbemCimOperations verboseoutput("Found pywbem version "+pywbemversion)
import pywbem.cim_http as PywbemCimHttp
import pywbem.exceptions as PywbemExceptions if '0.7.' in pywbemversion:
try:
conntest = pywbem.WBEMConnection(hosturl, (user,password))
c = conntest.EnumerateInstances('CIM_Card')
except:
#raise
verboseoutput("Connection error, disable SSL certificate verification (probably patched pywbem)")
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), no_verification=True)
else:
verboseoutput("Connection worked")
wbemclient = pywbem.WBEMConnection(hosturl, (user,password))
# pywbem 0.8.0 and later
else:
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), NS, no_verification=True)
# Add a timeout for the script. When using with Nagios, the Nagios timeout cannot be < than plugin timeout. # Add a timeout for the script. When using with Nagios, the Nagios timeout cannot be < than plugin timeout.
if on_windows == False and timeout > 0: if on_windows == False and timeout > 0:
@ -772,7 +767,7 @@ ExitMsg = ""
if vendor=='auto': if vendor=='auto':
try: try:
c=wbemclient.EnumerateInstances('CIM_Chassis') c=wbemclient.EnumerateInstances('CIM_Chassis')
except PywbemCimOperations.CIMError as args: except pywbem.cim_operations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ): if ( args[1].find('Socket error') >= 0 ):
print("UNKNOWN: {}".format(args)) print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
@ -781,15 +776,11 @@ if vendor=='auto':
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
else: else:
verboseoutput("Unknown CIM Error: %s" % args) verboseoutput("Unknown CIM Error: %s" % args)
except PywbemExceptions.ConnectionError as args: except pywbem._exceptions.ConnectionError as args:
GlobalStatus = ExitUnknown GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args)) print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus) sys.exit (GlobalStatus)
except PywbemExceptions.HTTPError as args: except pywbem.cim_http.AuthError as arg:
GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus)
except PywbemCimHttp.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")
@ -811,7 +802,7 @@ 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 PywbemCimOperations.CIMError as args: except pywbem._cim_operations.CIMError as args:
if ( args[1].find('Socket error') >= 0 ): if ( args[1].find('Socket error') >= 0 ):
print("UNKNOWN: {}".format(args)) print("UNKNOWN: {}".format(args))
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
@ -820,15 +811,11 @@ for classe in ClassesToCheck :
sys.exit (ExitUnknown) sys.exit (ExitUnknown)
else: else:
verboseoutput("Unknown CIM Error: %s" % args) verboseoutput("Unknown CIM Error: %s" % args)
except PywbemExceptions.ConnectionError as args: except pywbem._exceptions.ConnectionError as args:
GlobalStatus = ExitUnknown GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args)) print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus) sys.exit (GlobalStatus)
except PywbemExceptions.HTTPError as args: except pywbem._cim_http.AuthError as arg:
GlobalStatus = ExitUnknown
print("UNKNOWN: {}".format(args))
sys.exit (GlobalStatus)
except PywbemCimHttp.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")
@ -876,6 +863,7 @@ for classe in ClassesToCheck :
model = instance[u'Model'] model = instance[u'Model']
if model: if model:
verboseoutput(" Model = "+model) verboseoutput(" Model = "+model)
#server_info += model + ' s/n:'
server_info += model server_info += model
elif elementName == 'Server Blade' : elif elementName == 'Server Blade' :
@ -1079,7 +1067,7 @@ xdata['GlobalStatus'] = GlobalStatus
if GlobalStatus == ExitOK : if GlobalStatus == ExitOK :
if format == 'string': if format == 'string':
print("OK - Server: %s s/n: %s %s%s" % (server_info, SerialNumber, bios_info, perf)) print("OK - Server: %s %s %s%s" % (server_info, 's/n: ' + SerialNumber, bios_info, perf))
else: else:
xdataprint() xdataprint()