Problem with check_esxi_hardware.py


(Vacheslav) #1

Peace,
works great in command line only.
here is the output:

    (No output on stdout) stderr: Traceback (most recent call last):
    File "/usr/lib64/nagios/plugins//check_esxi_hardware.py", line 262, in <module>
    import pywbem
    File "/usr/lib64/python2.7/site-packages/pywbem/__init__.py", line 39, in <module>
    from .cim_operations import * # noqa: F403,F401

    File "/usr/lib64/python2.7/site-packages/pywbem/cim_operations.py", line 158, in <module>
    from ._recorder import LogOperationRecorder
    File "/usr/lib64/python2.7/site-packages/pywbem/_recorder.py", line 33, in <module>
    import yaml
    File "build/bdist.linux-x86_64/egg/yaml/__init__.py", line 14, in <module>
    File "build/bdist.linux-x86_64/egg/yaml/cyaml.py", line 5, in <module>
    File "build/bdist.linux-x86_64/egg/_yaml.py", line 7, in <module>
    File "build/bdist.linux-x86_64/egg/_yaml.py", line 4, in __bootstrap__
    File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 1226, in resource_filename
    self, resource_name
    File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 1743, in get_resource_filename
    self._extract_resource(manager, self._eager_to_zip(name))
    File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 1773, in _extract_resource
    self.egg_name, self._parts(zip_path)
    File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 1293, in get_cache_path
    self.extraction_error()
    File "/usr/lib64/python2.7/site-packages/pkg_resources/__init__.py", line 1273, in extraction_error
    raise err
    pkg_resources.ExtractionError: Can't extract file(s) to egg cache

    The following error occurred while trying to extract file(s)
    to the Python egg cache:

    [Errno 13] Permission denied: '/root/.cache'

    The Python egg cache directory is currently set to:

    /root/.cache/Python-Eggs

    Perhaps your account does not have write access to this directory?
    You can change the cache directory by setting the PYTHON_EGG_CACHE
    environment variable to point to an accessible directory.

I’ve spent days trying to install pywbem to point to user cache directory, obviously with no success.
here is my last attempt so far:

    sudo python2.7 setup.py install install_egg_info -d /home/nagios/.cache/Python-Eggs
    running install
    [pbr] Generating AUTHORS
    [pbr] AUTHORS complete (0.0s)
    running build
    running build_py
    running egg_info
    writing requirements to pywbem.egg-info/requires.txt
    writing pywbem.egg-info/PKG-INFO
    writing top-level names to pywbem.egg-info/top_level.txt
    writing dependency_links to pywbem.egg-info/dependency_links.txt
    [pbr] Reusing existing SOURCES.txt
    running build_scripts
    running install_lib
    creating /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/exceptions.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_listener.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_http.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_subscription_manager.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_operations.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_version.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/__init__.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_cliutils.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/tupleparse.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/mof_compiler.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_valuemapping.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/config.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_recorder.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_types.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_constants.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_utils.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/tupletree.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_nocasedict.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_statistics.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_server.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_xml.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/cim_obj.py -> /usr/lib64/python2.7/site-packages/pywbem
    copying build/lib/pywbem/_logging.py -> /usr/lib64/python2.7/site-packages/pywbem
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/exceptions.py to exceptions.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_listener.py to _listener.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_http.py to cim_http.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_subscription_manager.py to _subscription_manager.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_operations.py to cim_operations.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_version.py to _version.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/__init__.py to __init__.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_cliutils.py to _cliutils.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/tupleparse.py to tupleparse.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/mof_compiler.py to mof_compiler.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_valuemapping.py to _valuemapping.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/config.py to config.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_recorder.py to _recorder.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_types.py to cim_types.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_constants.py to cim_constants.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_utils.py to _utils.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/tupletree.py to tupletree.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_nocasedict.py to _nocasedict.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_statistics.py to _statistics.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_server.py to _server.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_xml.py to cim_xml.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/cim_obj.py to cim_obj.pyc
    byte-compiling /usr/lib64/python2.7/site-packages/pywbem/_logging.py to _logging.pyc
    running install_egg_info
    removing '/home/nagios/.cache/Python-Eggs/pywbem-0.12.1.dev23-py2.7.egg-info' (and everything under it)
    Copying pywbem.egg-info to /home/nagios/.cache/Python-Eggs/pywbem-0.12.1.dev23-py2.7.egg-info
    running install_scripts
    changing mode of /usr/bin/wbemcli to 755
    changing mode of /usr/bin/wbemcli.bat to 755
    changing mode of /usr/bin/mof_compiler to 755
    changing mode of /usr/bin/wbemcli.py to 755
    changing mode of /usr/bin/mof_compiler.bat to 755

The miracle question is: how to install pywbem to have the egg cache directory not in root?


(Michael Friedrich) #2

Never done it this way, is there a specific reason you cannot use pip install pywbem?


(Vacheslav) #3

pip uninstall pywbem
Cannot uninstall requirement pywbem, not installed

So I went to /usr/lib64/python2.7/site-packages/pywbem and deleted it.

su - nagios
Password:
nagios@nagios ~ $ mkvirtualenv -p python2.7 pywbem27
-su: mkvirtualenv: command not found
nagios@nagios ~ $ source ~/.bashrc
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/nagios/.virtualenvs/get_env_details
nagios@nagios ~ $ mkvirtualenv -p python2.7 pywbem27
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /home/nagios/.virtualenvs/pywbem27/bin/python2.7
Not overwriting existing python script /home/nagios/.virtualenvs/pywbem27/bin/python (you must use /home/nagios/.virtualenvs/pywbem27/bin/python2.7)
Installing setuptools, pip, wheel…done.

pip install pywbem
Requirement already satisfied: pywbem in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (0.12.3)
Requirement already satisfied: six>=1.10.0 in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (1.11.0)
Requirement already satisfied: pbr>=1.10.0 in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (4.0.4)
Requirement already satisfied: ply>=3.10 in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (3.11)
Requirement already satisfied: M2Crypto!=0.27.0,>=0.24.0; (python_version == “2.6” or python_version == “2.7”) and sys_platform != “win32” in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (0.30.1)
Requirement already satisfied: mock>=2.0.0 in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (2.0.0)
Requirement already satisfied: PyYAML>=3.12 in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from pywbem) (3.12)
Requirement already satisfied: typing in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from M2Crypto!=0.27.0,>=0.24.0; (python_version == “2.6” or python_version == “2.7”) and sys_platform != “win32”->pywbem) (3.6.4)
Requirement already satisfied: funcsigs>=1; python_version < “3.3” in ./.virtualenvs/pywbem27/lib/python2.7/site-packages (from mock>=2.0.0->pywbem) (1.0.2)

pip list
Package Version


funcsigs 1.0.2
M2Crypto 0.30.1
mock 2.0.0
pbr 4.0.4
pip 10.0.1
ply 3.11
pywbem 0.12.3
PyYAML 3.12
setuptools 39.2.0
six 1.11.0
typing 3.6.4
wheel 0.31.1

exit
su - root
Password:
nagios ~ # pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
certifi (2018.4.16)
cracklib (2.9.6)
Cython (0.25.2)
docutils (0.13.1)
extras (1.0.0)
file-magic (0.3.0)
fixtures (3.0.0)
gdbus-codegen (2.52.3)
gemato (13.0)
gentoolkit (0.4.2.post1)
greenlet (0.4.13)
isc (2.0)
java-config (2.2.0)
linecache2 (1.0.0)
logilab-common (1.2.2)
meson (0.46.1)
mimeparse (1.6.0)
mock (2.0.0)
nagios (0.0.8)
pbr (3.1.1)
pip (9.0.1)
ply (3.9)
portage (2.3.40)
pyblake2 (1.1.2)
pyegg (1.0)
pyelftools (0.24)
Pygments (2.2.0)
pyrsistent (0.13.0)
python-mimeparse (1.6.0)
python-subunit (1.2.0)
PyYAML (3.12)
setuptools (36.7.2)
six (1.11.0)
stevedore (1.28.0)
testtools (2.3.0)
traceback2 (1.4.0)
unittest2 (1.1.0)
virtualenv (15.1.0)
virtualenv-clone (0.2.6)
virtualenvwrapper (4.8.2)

su - nagios
./check_esxi_hardware.py
Traceback (most recent call last):
File “./check_esxi_hardware.py”, line 262, in
import pywbem
ImportError: No module named pywbem
nagios@nagios /usr/lib64/nagios/plugins $

so although /etc/nagios is owned by nagios:nagios and so is the script it seems to be wanting to run as root.
install as root?


(Michael Friedrich) #4

The plugin call doesn’t know anything about your virtualenv, you did not source it beforehand.


(Vacheslav) #5

so what is the solution?


(Michael Friedrich) #6

Dunno. Maybe try to source virtualenv prior to calling the plugin, or install as root.


(Vacheslav) #7

Thanks for trying to help out, Got it solved by adding
start_stop_daemon_args="-e HOME=/home/nagios"
in /etc/conf,d/nagios, exclusive to gentoo. And since I now have to go to icinga forums to get support, so I might as well migrate to icinga!


(Michael Friedrich) #8

Oh, so that the daemon knows about its home directory and the local installed libraries. Makes sense, glad you figured it out :slight_smile: