Skip to content
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

functional degradation #11

Open
wavilen opened this issue Feb 20, 2014 · 8 comments
Open

functional degradation #11

wavilen opened this issue Feb 20, 2014 · 8 comments

Comments

@wavilen
Copy link

wavilen commented Feb 20, 2014

I writed the function

def get(ip, community):                                                                   
    load(                                                                                 
        os.path.join(                                                                     
            CONF['abs_path'],                                                             
            "app/snmp/mib/SNMPv2-SMI.my"                                                  
        )                                                                                 
    )                                                                                     
    load(                                                                                 
        os.path.join(                                                                     
            CONF['abs_path'],                                                             
            "app/snmp/mib/BGP4-MIB.my"                                                    
        )                                                                                 
    )                                                                                     
    m = M(ip, community, 2)                                                               
    result = {}                                                                           
    try:                                                                                  
        result = dict([(str(idx), {'value': str(m.bgpPeerIdentifier[idx])})               
            for idx in m.bgpPeerIdentifier])                                              
    except SNMPException, err:                                                            
        print(err)                                                                        

    return result                                                                         
  • for snimpy==0.6.4:
    result is a dict with necessary data
  • for snimpy==0.7.0:
    TypeError: initializer for ctype 'char *' must be a str or list or tuple, not unicode
  • for snimpy==0.8.0:
    OIDs are not increasing
    {}

As example: the snmpwalk tool in shell returned also necessary data, but append similar error.

Sorry for my poor English.

@vincentbernat
Copy link
Owner

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.

@wavilen
Copy link
Author

wavilen commented Feb 20, 2014

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>

@vincentbernat
Copy link
Owner

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.

@wavilen
Copy link
Author

wavilen commented Feb 20, 2014

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

@vincentbernat
Copy link
Owner

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.

@wavilen
Copy link
Author

wavilen commented Feb 20, 2014

    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

@wavilen
Copy link
Author

wavilen commented Feb 20, 2014

Do not worry if nothing happened. All other libraries (netsnmp, pysnmp) do not deal with this problem. I now use snmpwalk via subprocess.Popen().

@vincentbernat
Copy link
Owner

OK, I need to test that on my side. I keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants