Skip to content

Commit

Permalink
Remove python2 and pywbem 0.7.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Napsty committed Oct 25, 2024
1 parent 7aaaae4 commit e63f9fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 130 deletions.
122 changes: 20 additions & 102 deletions .github/workflows/python3check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 12 additions & 28 deletions check_esxi_hardware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
#
# Script for checking global health of host running VMware ESX/ESXi
Expand All @@ -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
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e63f9fe

Please sign in to comment.