Napsty / check_esxi_hardware

Monitoring Plugin to check the hardware of VMware ESXi servers.
https://www.claudiokuenzler.com/monitoring-plugins/check_esxi_hardware.php
70 stars 18 forks source link

pkg_resources is deprecated #72

Open p-try opened 9 months ago

p-try commented 9 months ago

Before actually creating a new issue I confirm, I have read the FAQ (https://www.claudiokuenzler.com/blog/308/check-esxi-hardware-faq-frequently-asked-questions): Y I confirm, I have restarted the CIM server (/etc/init.d/sfcbd-watchdog restart) on the ESXi server and the problem remains: Y I confirm, I have cleared the server's local IPMI cache (localcli hardware ipmi sel clear) and restarted the services (/sbin/services.sh restart) on the ESXi server and the problem remains: Y

Describe the bug The script uses the following code to check the version of pywbem:

# 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__
verboseoutput("Found pywbem version "+pywbemversion)

A deprecation warning appears: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

Expected behavior Output should not contain the deprecation warning.

Versions:

Napsty commented 9 months ago

The PR is good, however it breaks backward compatibility with older systems, using an older Python version. importlib.metadata (https://docs.python.org/3/library/importlib.metadata.html) was added in Python 3.8. Some users (unfortunately) still use older systems with an older Python version - mainly RHEL 7 which ships Python 2.7 and 3.6 by default.

RHEL 7 is EOL end of June this year. I guess we can in July make a new release of the check_esxi_hardware plugin and set new requirements. EOL systems would no longer be supported and need to use an older version of the plugin.

So let's keep this in "backlog" and look at this again later this year when the last "big" OS releases stop supporting very old Python versions.

In the meantime, as a workaround, you could ignore the deprecation warnings: https://stackoverflow.com/questions/879173/how-to-ignore-deprecation-warnings-in-python

emlowe commented 1 month ago

Ping about this - RHEL 7 and python 3.7 (and earlier) are out of support now (Oct 2024)

Napsty commented 1 month ago

Thanks for the reminder. Yes, it's time now. I will work on this soon.

Napsty commented 4 weeks ago

Alright there are a couple of things to consider:

Now looking at this and assuming pywbem 0.7.0 is now definitely gone in active setups, I guess it's safe to remove the "different pywbem version handling" in the plugin. If, in the future, we run into new compatibility issues between certain pywbem versions, then we can use pywbem.__version__ which was added after pywbem 0.7.0 (don't remember the exact release).

Besides this, all active Linux distributions, including LTS releases, come with python3. There might still be some older LTS releases out there which ship both python2 and python3, but this means that python3 is available on all active setups. This means we can also get rid of the "python2 to python3 translation" (for the print function).

Napsty commented 4 weeks ago

All, please have a look at #73 and let me know your thoughts. In the meantime I deploy the python3 only plugin on my monitoring environments to verify everything works.

Napsty commented 3 weeks ago

FYI, I plan to release the new version (python3 only) on November 1st 2024, unless a blocker-comment comes up in between.