Open wavilen opened 10 years ago
I need to look a bit more why the error was silently suppressed in 0.6.4 but the behaviour in 0.8.0 seems correct. Since you get an exception, you never have a change to affect the result to result
. You should so something like that instead:
result=[]
try:
for idx in m.bgpPeerIdentifier:
result.append((str(idx), str(m.bgpPeerIdentifier[idx])))
except SNMPException as err:
print(err)
return dict(result)
BTW, if you try snmpwalk
with -Cc
, do you get more results? This could be something that snimpy could do too.
Thanks for your answer.
I changed as you suggested, but the same result.
snmpwalk -Cc
goes into an infinite loop.
without -Cc
args return like:
...
bgpPeerIdentifier....
...
bgpPeerIdentifier.<IP1>= IpAddress: <IP2>
Error: OID not increasing: bgpPeerIdentifier.<IP3>
>= bgpPeerIdentifier.<IP1>
Could you remove the "print(err)" and copy/paste the exception you get? I would like to know on which part the exception is happening.
I'm not quite sure which of the variants...
m = M(ip, community, 2)
result = []
for idx in m.bgpPeerIdentifier:
result.append((str(idx), {'value': str(m.bgpPeerIdentifier[idx])}))
return dict(result)
for snimpy==0.8.0:
python -m app.snmp.bgp
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/opt/zbxsync/env/app/snmp/bgp.py", line 37, in <module>
main()
File "/opt/zbxsync/env/app/snmp/bgp.py", line 33, in main
result_get_func = get(IP_Redback_Networks_SmartEdge, Community)
File "/opt/zbxsync/env/app/snmp/bgp.py", line 22, in get
for idx in m.bgpPeerIdentifier:
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/manager.py", line 362, in __iter__
for k, _ in self.iteritems():
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/manager.py", line 373, in iteritems
for noid, result in self.session.walk(oid):
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/snmp.py", line 240, in walk
return self._op(self._cmdgen.bulkCmd, *args)
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/snmp.py", line 198, in _op
raise SNMPException(str(errorIndication))
snimpy.snmp.SNMPException: OIDs are not increasing
Could you try:
m = M(ip, community, 2)
m._session.bulk = False
result = []
for idx in ...
It seems we get the error because of the use of GETBULK for walking. Also, please try with version=1, just to be sure that GETBULK gets disabled.
m = M(ip, community, 1)
m._session.bulk = False
result = []
for idx in m.bgpPeerIdentifier:
result.append((str(idx), {'value': str(m.bgpPeerIdentifier[idx])}))
return dict(result)
python -m app.snmp.bgp
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/opt/zbxsync/env/app/snmp/bgp.py", line 40, in <module>
main()
File "/opt/zbxsync/env/app/snmp/bgp.py", line 36, in main
result_get_func = get(IP_Redback_Networks_SmartEdge, Community)
File "/opt/zbxsync/env/app/snmp/bgp.py", line 29, in get
for idx in m.bgpPeerIdentifier:
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/manager.py", line 362, in __iter__
for k, _ in self.iteritems():
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/manager.py", line 373, in iteritems
for noid, result in self.session.walk(oid):
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/snmp.py", line 238, in walk
return self._op(self._cmdgen.nextCmd, *oids)
File "/opt/zbxsync/env/local/lib/python2.7/site-packages/snimpy/snmp.py", line 198, in _op
raise SNMPException(str(errorIndication))
snimpy.snmp.SNMPException: OIDs are not increasing
Do not worry if nothing happened. All other libraries (netsnmp, pysnmp) do not deal with this problem. I now use snmpwalk
via subprocess.Popen().
OK, I need to test that on my side. I keep you posted.
I writed the function
As example: the snmpwalk tool in shell returned also necessary data, but append similar error.
Sorry for my poor English.