cancel
Showing results for 
Search instead for 
Did you mean: 

How to import and install third party python modules in an EXOS switch

How to import and install third party python modules in an EXOS switch

DanielDelgado
New Contributor
Hello everybody.

I am trying to do an script to write in an OID mib a value. I don`t know if this is possible from an EXOS switch.I did not found any command to do this, so I thought to write an script to make an snmp set in an "free" OID and consult it periodically with an SNMP TOOL( not the XMC..).

I wish to know is it is possible to install easysnmp python module in an EXOS switch, or if it is possible to install a third party python module. I found in the "Python Getting Started Guide" that it can be imported modules like this:

"Adding Third-Party Modules
One very nice thing about Python is its large community of programmers that have been around for many years. Because of this, many Python libraries and documentation exist, from Scientific Calculation to Game Programming.
For your need, you may have to install new libraries on EXOS to use them for your code. This can be easily accomplished by TFTP-ing the files in the /config directory. Python will automatically search that directory. This is the default directory where files are sent when you do a tftp.
As an example, if you need the eventd.py program and its configuration file eventd.conf, you simply tftp both files to the switch. You need a TFTP server on your PC, pointing to the directory where the files are located, and you type the tftp command on the switch.
tftp 192.168.56.1 –g –r eventd.py
tftp 192.168.56.1 –g –r eventd.conf
You can now use the library in your Python script."


But I can not make it run with importing easysnmp.

Any advise?

Thanks a lot.
Daniel.
4 REPLIES 4

BrandonC
Extreme Employee
It is possible to import third party python libraries, assuming they are pure Python2. All you need to do is copy the directory and all .py files inside it (including __init__.py) to the config directory of the switch. You can then import the library as normal inside your Python script, since /usr/local/cfg/ is included in the path.

For example, assuming a library directory 'foo', with .py files '__init__.py', 'bar.py', 'baz.py', and 'bat.py' inside it, first create the directory 'foo' with 'mkdir foo'. Then, 'cd foo' and copy the .py files in to it.

Once you've done this, 'cd' back to /usr/local/cfg/, and create your python script. You will be able to 'import foo'.

As for 'easysnmp' specifically, this library is not able to be used because it includes some C code that must be compiled first (You can see that in the easysnmp GitHub repo). EXOS does not allow the user to compile C code, so the we can't easily use easysnmp in EXOS. Stephen's example above is probably the easiest option in this case.

Hope that didn't confuse things too much.

Tomasz
Valued Contributor II
Hi Daniel,

Theoretically you can use your scripts or NMS FlexViews or 3rd party tool to modify any R/W OIDs, and you can use your scripts or NMS FlexViews or 3rd party tool to view those OIDs. 🙂

Hope that helps,
Tomasz

DanielDelgado
New Contributor
Hi Stephen.

Thanks for your help!!

It was really usefull!

Just in case you can help me... I am starting to use MIBS + Scripts in EXOS. Do you know if it is possible to fill the value of an OID from the own EXOS switch?

I mean.. I' found that there are a mib_2 tree called "iso.org.dod.internet.mgmt.mib-2.scriptMIB
1.3.6.1.2.1.64"
"
scriptMIB OBJECT-TYPE
SYNTAX Module Identity
  • DESCRIPTION This MIB module defines a set of objects that allow to
  • delegate management scripts to distributed managers.
::= { mib-2 64 }"

I'd like to fill this OID with values from my scripts, and be able to get these data from an external SNMP TOOL. Do you think this is possible?

I am looking for information.. but nothing found yet..

Thanks in advance!
Daniel

StephenW
Extreme Employee
I don't think you can import new libraries.

But you can do a SNMP set with the below python code. This code changes the snmp sysname.

code:
from pysnmp.entity.rfc3413.oneliner import cmdgen

cmdGen = cmdgen.CommandGenerator()

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.CommunityData('private'),
cmdgen.UdpTransportTarget(('192.168.1.66', 161)),
('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('Testing123'))
)

# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))




The CLI ouput looks like this

code:
SW02.10 # load sc snmp.py
1.3.6.1.2.1.1.5.0 = Testing123
SW02.11 #
GTM-P2G8KFN