From e63f9fee6a83e00a9d03014cb0328ac2d66687bc Mon Sep 17 00:00:00 2001 From: Napsty Date: Fri, 25 Oct 2024 14:42:19 +0200 Subject: [PATCH] Remove python2 and pywbem 0.7.0 compatibility --- .github/workflows/python3check.yml | 122 +++++------------------------ check_esxi_hardware.py | 40 +++------- 2 files changed, 32 insertions(+), 130 deletions(-) diff --git a/.github/workflows/python3check.yml b/.github/workflows/python3check.yml index dba14d2..868d9dd 100644 --- a/.github/workflows/python3check.yml +++ b/.github/workflows/python3check.yml @@ -6,109 +6,27 @@ name: Python3 check on: [push, pull_request] jobs: - simple-output: + simple-job: 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-*' + python3-pywbem-latest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + 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:${PYTHONPATH} + - 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 diff --git a/check_esxi_hardware.py b/check_esxi_hardware.py index badd256..2b651d2 100755 --- a/check_esxi_hardware.py +++ b/check_esxi_hardware.py @@ -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 @@ -293,17 +293,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 +733,10 @@ def handler(signum, frame): 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: