import external python library (pysnmp) in Cameo Systems Modeler 18.1

709 views Asked by At

I'm trying to execute some Python code that utilizes the pysnmp Python library in a Cameo Systems Modeler (CSM) project, more specifically in a model "activity". In this same model activity I can run other python code just fine, such as:

import sys
     
print "imported sys"
print "len(sys.argv): ", len(sys.argv)
for arg in sys.argv:
    print arg
print "tried to print sys.argv args..."

This runs fine in CSM, but when I try to run a script that uses an external library such as Pysnmp I am unable to. For instance, I can run the following Python code (sample from pysnmp docs) on my Windows CMD:

# from the pysnmp site, using SNMP v2c
from pysnmp.entity.rfc3413.oneliner import cmdgen

def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex,
          varBinds, cbCtx):
    if errorIndication:
        print(errorIndication)
        return
    if errorStatus:
        print('%s at %s' % \
            (errorStatus.prettyPrint(),
             errorIndex and varBinds[int(errorIndex)-1] or '?')
        )
        return
    
    for oid, val in varBinds:
        if val is None:
            print(oid.prettyPrint())
        else:
            print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))

cmdGen  = cmdgen.AsynCommandGenerator()

for varName in ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
                 cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0),
                 cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0) ):
    cmdGen.getCmd(
        cmdgen.CommunityData('public'),
        cmdgen.UdpTransportTarget(('127.0.0.1', 161)),
        (varName,),
        (cbFun, None)
    )

cmdGen.snmpEngine.transportDispatcher.runDispatcher()

My issue is that I don't know how to import and utilize an external library like Pysnmp in a Cameo Systems Modeler (CSM) project. I tried importing the library through the project options as specified in the User Manual: "options" > "project" > "general project options" > "external libraries" and adding a .zip of the script I need (per the code above: pysnmp.entity.rfc3413.oneliner). One observation I made is that in the first code block above I am able to import the "sys" library, but is that a .jar or .py? Can I possibly do something similar for Pysnmp and other external libs?

0

There are 0 answers