TECHZEN Zenoss User Community ARCHIVE  

Zenoss 4.2.5 - install extra libraries for use in a zenpack

Subject: Zenoss 4.2.5 - install extra libraries for use in a zenpack
Author: Pheripheral Pheripheral
Posted: 2019-02-22 10:14

Hi,
I'm attempting to add some code to a zenpack that will allow me to use some decryption on some config values read out from a file.

The code we're using to do this uses the python cryptography library.

I can get this working as root user on my zenoss 4.2.5 centos box by installing the library via pip in some standalone python scripts with code like this.
from cryptography.fernet import Fernet
f = Fernet(encryptionKey)
unencryptedvalue = f.decrypt(encryptedvalue)

but i'm struggling to get it to work once i add it as part of my zenpack code.
I get errors that the module cryptography.fernet cannot be import - i.e. it can't see my packages.

I'm not sure if the issue is when i installed as root the libraries end up in the out of the box python26 area but zenoss is actually using the /opt/zenoss/lib/python and python2.7 area to pick up its packages.

I did do some experimenting with various attempts to install the packages (cryptography pulls in some dependencies - six, idna, pyasn1, enum34, ipaddress, pycparser, cffi) in the python27 area as the zenoss user via either manually running the setup.py files for each packages or running a pip explicitly using the /opt/zenoss/bin/python like this:
/opt/zenoss/bin/python -m pip install cryptography

but doing this seems to get me in a mess each time with zenoss itself starting to throw problems up when i restart the daemons. (Fixed by reverting to my pre install attempt snapshot of the VM)

So i'm not quite sure how i'm supposed to install the libraries so that they work with the zenpack and not break zenoss in the process!
The six library seems to cause issues as there now seem to be vaiours versions of it spread across various directories...

Could i solve this by adding the libraries directly to my zenpack so that only that zenpack code uses them? (similar to the advice in this thread - How to add required Python module to ZenPack)

Any advice appreciated

Thanks
Dafydd



------------------------------
Pheripheral
------------------------------


Subject: RE: Zenoss 4.2.5 - install extra libraries for use in a zenpack
Author: Jane Curry
Posted: 2019-03-14 10:42

I have certainly had success with the link that you quoted.  You will need to add all the packages that you need, including any pre-reqs / co-reqs.
Cheers,
jane

------------------------------
Jane Curry
Skills 1st United Kingdom
jane.curry@skills-1st.co.uk
------------------------------


Subject: RE: Zenoss 4.2.5 - install extra libraries for use in a zenpack
Author: Pheripheral Pheripheral
Posted: 2019-03-20 06:22

Thanks
I gave the 'include libraries in the zenpack' a go but did not quite get it working as still ran into some issues where code was pulling in the wrong version of things, mostly the six.py stuff.

Eventually rewoked the code to use a different encryption library and found a cleaner solution that needed less dependencies/ dependencies that did not interfer with the existing zenoss code (essentially using pycryptodome library instead of cryptography)


------------------------------
Pheripheral Pheripheral
------------------------------


Subject: RE: Zenoss 4.2.5 - install extra libraries for use in a zenpack
Author: Jay Stanley
Posted: 2019-04-03 08:23

I always add my libs to my ZenPack under a directory lib, then import that copy. Then I never have to worry about the lib being installed or not, everything needed is contained in the ZenPack.

For example, if I needed python requests, I would snag the repo and then add it to ZenPacks.jstanley.MyZenPack/ZenPacks/jstanley/MyZenPack/lib


------------------------------
jstanley
------------------------------


< Previous
ZenPacks.CS.NetApp.SevenMode
  Next
ZenPack devel, how is the logic to generate events
>