Skip to content

Commit 29b32b7

Browse files
authored
Remove python2 and pywbem 0.7.0 compatibility (#73)
Remove python2 and pywbem 0.7.0 compatibility
1 parent 7aaaae4 commit 29b32b7

File tree

3 files changed

+28
-215
lines changed

3 files changed

+28
-215
lines changed

.github/workflows/python2check.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/python3check.yml

Lines changed: 11 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,16 @@ name: Python3 check
66
on: [push, pull_request]
77

88
jobs:
9-
simple-output:
9+
python3-pywbem-latest:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Simple hello world
13-
run: echo "Hello World"
14-
# python3-pywbem-latest:
15-
# runs-on: ubuntu-latest
16-
# steps:
17-
# - uses: actions/checkout@v1
18-
# - uses: actions/setup-python@v1
19-
# with:
20-
# python-version: '3.8'
21-
# - name: Install latest pywbem from pip
22-
# run: |
23-
# sudo apt-get install -qq -yy python3-pip
24-
# pip3 install pywbem
25-
# - name: Set environment PYTHONPATH
26-
# run: |
27-
# export PYTHONPATH=/opt/hostedtoolcache/Python/3.8.0/x64/lib/python3.8/site-packages
28-
# - name: Verify python sys.path
29-
# run: (echo "import sys"; echo "print(', '.join(sys.path))") | python
30-
# - name: Launch script with --help
31-
# run: |
32-
# ./check_esxi_hardware.py --help
33-
# python3-pywbem-08:
34-
# runs-on: ubuntu-latest
35-
# steps:
36-
# - uses: actions/checkout@v1
37-
# - uses: actions/setup-python@v1
38-
# with:
39-
# python-version: '3.x'
40-
# - name: Install latest pywbem from pip
41-
# run: |
42-
# sudo apt-get install -qq -yy python3-pip
43-
# pip3 install pywbem==0.8.4
44-
# - name: Set environment PYTHONPATH
45-
# run: |
46-
# export PYTHONPATH=/opt/hostedtoolcache/Python
47-
# - name: Launch script with --help
48-
# run: |
49-
# ./check_esxi_hardware.py --help
50-
# python3-pywbem-012:
51-
# runs-on: ubuntu-latest
52-
# steps:
53-
# - uses: actions/checkout@v1
54-
# - uses: actions/setup-python@v1
55-
# with:
56-
# python-version: '3.x'
57-
# - name: Install latest pywbem from pip
58-
# run: |
59-
# sudo apt-get install -qq -yy python3-pip
60-
# pip3 install pywbem==0.12.6
61-
# - name: Set environment PYTHONPATH
62-
# run: |
63-
# export PYTHONPATH=/opt/hostedtoolcache/Python
64-
# - name: Launch script with --help
65-
# run: |
66-
# ./check_esxi_hardware.py --help
67-
# python3-pywbem-013:
68-
# runs-on: ubuntu-latest
69-
# steps:
70-
# - uses: actions/checkout@v1
71-
# - uses: actions/setup-python@v1
72-
# with:
73-
# python-version: '3.x'
74-
# - name: Install latest pywbem from pip
75-
# run: |
76-
# sudo apt-get install -qq -yy python3-pip
77-
# pip3 install pywbem==0.13.1
78-
# - name: Set environment PYTHONPATH
79-
# run: |
80-
# export PYTHONPATH=/opt/hostedtoolcache/Python
81-
# - name: Launch script with --help
82-
# run: |
83-
# ./check_esxi_hardware.py --help
84-
# python3-pywbem-014:
85-
# runs-on: ubuntu-latest
86-
# steps:
87-
# - uses: actions/checkout@v1
88-
# - uses: actions/setup-python@v1
89-
# with:
90-
# python-version: '3.x'
91-
# - name: Install latest pywbem from pip
92-
# run: |
93-
# sudo apt-get install -qq -yy python3-pip
94-
# pip3 install pywbem==0.14.6
95-
# - name: Set environment PYTHONPATH
96-
# run: |
97-
# export PYTHONPATH=/opt/hostedtoolcache/Python
98-
# - name: Launch script with --help
99-
# run: |
100-
# ./check_esxi_hardware.py --help
101-
# find-pywbem:
102-
# runs-on: ubuntu-latest
103-
# steps:
104-
# - uses: actions/checkout@v1
105-
# - uses: actions/setup-python@v1
106-
# with:
107-
# python-version: '3.x'
108-
# - name: Install latest pywbem from pip
109-
# run: |
110-
# sudo apt-get install -qq -yy python-pip
111-
# pip install pywbem
112-
# - name: Find pywbem module
113-
# run: |
114-
# find / -name 'pywbem-*'
12+
- uses: actions/checkout@v4
13+
- name: Install latest pywbem from pip
14+
run: |
15+
sudo apt-get install -qq -yy python3 python3-pip
16+
pip3 install pywbem
17+
- name: Verify python sys.path
18+
run: (echo "import sys"; echo "print(', '.join(sys.path))") | python3
19+
- name: Launch script with --help
20+
run: |
21+
./check_esxi_hardware.py --help

check_esxi_hardware.py

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# -*- coding: UTF-8 -*-
33
#
44
# Script for checking global health of host running VMware ESX/ESXi
@@ -22,7 +22,7 @@
2222
# Copyright (c) 2008 David Ligeret
2323
# Copyright (c) 2009 Joshua Daniel Franklin
2424
# Copyright (c) 2010 Branden Schneider
25-
# Copyright (c) 2010-2022 Claudio Kuenzler
25+
# Copyright (c) 2010-2024 Claudio Kuenzler
2626
# Copyright (c) 2010 Samir Ibradzic
2727
# Copyright (c) 2010 Aaron Rogers
2828
# Copyright (c) 2011 Ludovic Hutin
@@ -40,12 +40,11 @@
4040
# Copyright (c) 2020 Luca Berra
4141
# Copyright (c) 2022 Marco Markgraf
4242
#
43-
# The VMware 4.1 CIM API is documented here:
44-
# http://www.vmware.com/support/developer/cim-sdk/4.1/smash/cim_smash_410_prog.pdf
45-
# http://www.vmware.com/support/developer/cim-sdk/smash/u2/ga/apirefdoc/
46-
#
47-
# The VMware 5.5 and above CIM API is documented here:
48-
# https://code.vmware.com/apis/207/cim
43+
# The VMware CIM API is documented here (as of October 2024):
44+
# https://docs.vmware.com/en/VMware-vSphere/7.0/vsphere-cim-smash-server-management-api-programming-guide/GUID-2725D01E-AE02-4EF2-9E98-5AB82AA0349A.html
45+
46+
# The CIM classes are documented here (as of October 2024):
47+
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/27c1c014-7315-4d6b-8e6b-292130a79b3c/36aca268-99fa-4916-b993-a077de55cbf1/CIM_API_Reference/index.html
4948
#
5049
# This monitoring plugin is maintained and documented here:
5150
# https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
@@ -293,17 +292,21 @@
293292
#@ Author : Claudio Kuenzler
294293
#@ Reason : Fix bug when missing S/N (issue #68)
295294
#@---------------------------------------------------
295+
#@ Date : 20241025
296+
#@ Author : Claudio Kuenzler
297+
#@ Reason : Fix pkg_resources deprecation warning
298+
# Remove python2 compatibility
299+
# Remove pywbem 0.7.0 compatibility
300+
#@---------------------------------------------------
296301

297-
from __future__ import print_function
298302
import sys
299303
import time
300304
import pywbem
301305
import re
302-
import pkg_resources
303306
import json
304307
from optparse import OptionParser,OptionGroup
305308

306-
version = '20221230'
309+
version = '20241025'
307310

308311
NS = 'root/cimv2'
309312
hosturl = ''
@@ -729,30 +732,10 @@ def handler(signum, frame):
729732
ignore_list.append("System Chassis 1 Chassis Intru: Unknown")
730733

731734
# connection to host
732-
verboseoutput("Connection to "+hosturl)
733-
# pywbem 0.7.0 handling is special, some patched 0.7.0 installations work differently
734-
try:
735-
pywbemversion = pywbem.__version__
736-
except:
737-
pywbemversion = pkg_resources.get_distribution("pywbem").version
738-
else:
739-
pywbemversion = pywbem.__version__
735+
pywbemversion = pywbem.__version__
740736
verboseoutput("Found pywbem version "+pywbemversion)
741-
742-
if '0.7.' in pywbemversion:
743-
try:
744-
conntest = pywbem.WBEMConnection(hosturl, (user,password))
745-
c = conntest.EnumerateInstances('CIM_Card')
746-
except:
747-
#raise
748-
verboseoutput("Connection error, disable SSL certificate verification (probably patched pywbem)")
749-
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), no_verification=True)
750-
else:
751-
verboseoutput("Connection worked")
752-
wbemclient = pywbem.WBEMConnection(hosturl, (user,password))
753-
# pywbem 0.8.0 and later
754-
else:
755-
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), NS, no_verification=True)
737+
verboseoutput("Connection to "+hosturl)
738+
wbemclient = pywbem.WBEMConnection(hosturl, (user,password), NS, no_verification=True)
756739

757740
# Add a timeout for the script. When using with Nagios, the Nagios timeout cannot be < than plugin timeout.
758741
if on_windows == False and timeout > 0:

0 commit comments

Comments
 (0)