-
-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readNextMibObjects not found from class MibInstrumController #383
Comments
Hi, I have stumbled upon this problem too. I assume the problem is that the example shown there is not for the same version as you (and I) have. Following example should do the same, which I found explicitly under 4.4.10 version: """
Implementing MIB objects
++++++++++++++++++++++++
This script explains how SNMP Agent application could model
real-world data as Managed Objects defined in MIB.
"""#
from pysnmp.smi import builder
# MIB Builder is normally pre-created by SNMP engine
mibBuilder = builder.MibBuilder()
#
# This may be done in a stand-alone file and then loaded up
# by SNMP Agent
#
# A base class for a custom Managed Object
MibScalarInstance, = mibBuilder.importSymbols(
'SNMPv2-SMI', 'MibScalarInstance'
)
# Managed object specification
sysLocation, = mibBuilder.importSymbols('SNMPv2-MIB', 'sysLocation')
# Custom Managed Object
class MySysLocationInstance(MibScalarInstance):
# noinspection PyUnusedLocal
def readGet(self, name, *args):
# Just return a custom value
return name, self.syntax.clone('The Leaky Cauldron')
sysLocationInstance = MySysLocationInstance(
sysLocation.name, (0,), sysLocation.syntax
)
# Register Managed Object with a MIB tree
mibBuilder.exportSymbols(
# '__' prefixed MIB modules take precedence on indexing
'__MY-LOCATION-MIB', sysLocationInstance=sysLocationInstance
)
if __name__ == '__main__':
#
# This is what is done internally by Agent.
#
from pysnmp.smi import instrum, exval
mibInstrum = instrum.MibInstrumController(mibBuilder)
print('Remote manager read access to MIB instrumentation (table walk)')
oid, val = (), None
while 1:
oid, val = mibInstrum.readNextVars(((oid, val),))[0]
if exval.endOfMib.isSameTypeWith(val):
break
print(oid, val.prettyPrint()) |
That doc site you access was mistakenly linked to the master branch which contains a newer PySNMP version with many breaking changes. For 4.4.12 sample code, you should instead take a look at https://github.com/etingof/pysnmp/tree/v4.4.12/examples/smi/agent |
After closing #429, time to revisit this. Ilya attempted to replace the old MIB-related infrastructure with a new one on the master branch for his release 5.0. However, as new maintainers, my team carefully evaluated many of his works and determined this new attempt was a total failure, and even simple test cases couldn’t pass. So we didn't pick them up in recent releases (6.x/7.x) right now. Please upgrade from 4.x, and use the latest documentation site to guide your code upon PySNMP, |
I'm a newbie with PySNMP, I'm trying to follow this example https://pysnmp.readthedocs.io/en/latest/examples/smi/agent/implementing-mib-objects.html. But when I run the script I got this error:
Traceback (most recent call last): File "v1-trap.py", line 43, in <module> mibInstrum.readNextMibObjects(*app_context['varBinds'], cbFun=cbFun, app=app_context) AttributeError: 'MibInstrumController' object has no attribute 'readNextMibObjects'
I'm using Python 3.8 and install pysnmp by issuing this command:
pip install pysnmp
, the version of pysnmp is 4.4.12Note that, when I browsed this repo I found that on branch 4.4.12 the method above is missing so how can I follow the example that mentioned above? Thanks.
The text was updated successfully, but these errors were encountered: