1
0
mirror of https://github.com/Napsty/check_esxi_hardware.git synced 2025-01-02 06:22:29 +01:00

Remove python2 and pywbem 0.7.0 compatibility (#73)

Remove python2 and pywbem 0.7.0 compatibility
This commit is contained in:
Claudio Kuenzler 2024-11-29 08:20:00 +01:00 committed by GitHub
parent 7aaaae4337
commit 29b32b785e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 215 deletions

View File

@ -1,77 +0,0 @@
# @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,109 +6,16 @@ name: Python3 check
on: [push, pull_request]
jobs:
simple-output:
python3-pywbem-latest:
runs-on: ubuntu-latest
steps:
- name: Simple hello world
run: echo "Hello World"
# python3-pywbem-latest:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-python@v1
# with:
# python-version: '3.8'
# - 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-*'
- uses: actions/checkout@v4
- name: Install latest pywbem from pip
run: |
sudo apt-get install -qq -yy python3 python3-pip
pip3 install pywbem
- name: Verify python sys.path
run: (echo "import sys"; echo "print(', '.join(sys.path))") | python3
- name: Launch script with --help
run: |
./check_esxi_hardware.py --help

View File

@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
#
# Script for checking global health of host running VMware ESX/ESXi
@ -22,7 +22,7 @@
# Copyright (c) 2008 David Ligeret
# Copyright (c) 2009 Joshua Daniel Franklin
# Copyright (c) 2010 Branden Schneider
# Copyright (c) 2010-2022 Claudio Kuenzler
# Copyright (c) 2010-2024 Claudio Kuenzler
# Copyright (c) 2010 Samir Ibradzic
# Copyright (c) 2010 Aaron Rogers
# Copyright (c) 2011 Ludovic Hutin
@ -40,12 +40,11 @@
# Copyright (c) 2020 Luca Berra
# Copyright (c) 2022 Marco Markgraf
#
# 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/smash/u2/ga/apirefdoc/
#
# The VMware 5.5 and above CIM API is documented here:
# https://code.vmware.com/apis/207/cim
# The VMware CIM API is documented here (as of October 2024):
# https://docs.vmware.com/en/VMware-vSphere/7.0/vsphere-cim-smash-server-management-api-programming-guide/GUID-2725D01E-AE02-4EF2-9E98-5AB82AA0349A.html
# 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
#
# This monitoring plugin is maintained and documented here:
# https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
@ -293,17 +292,21 @@
#@ Author : Claudio Kuenzler
#@ Reason : Fix bug when missing S/N (issue #68)
#@---------------------------------------------------
#@ Date : 20241025
#@ Author : Claudio Kuenzler
#@ Reason : Fix pkg_resources deprecation warning
# Remove python2 compatibility
# Remove pywbem 0.7.0 compatibility
#@---------------------------------------------------
from __future__ import print_function
import sys
import time
import pywbem
import re
import pkg_resources
import json
from optparse import OptionParser,OptionGroup
version = '20221230'
version = '20241025'
NS = 'root/cimv2'
hosturl = ''
@ -729,30 +732,10 @@ if not get_intrusion:
ignore_list.append("System Chassis 1 Chassis Intru: Unknown")
# connection to host
verboseoutput("Connection to "+hosturl)
# 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
else:
pywbemversion = pywbem.__version__
pywbemversion = pywbem.__version__
verboseoutput("Found pywbem version "+pywbemversion)
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)
verboseoutput("Connection to "+hosturl)
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.
if on_windows == False and timeout > 0: