0

I've got 3 switches I'm trying to get SNMP data from. Every switch does respond from time to time, but which switches respond depends upon the order I'm querying them. I'm using easysnmp.Session.

My code (passwords obviously not shown):

import easysnmp

switches_dns1 = {
            "switch1": "switch-mBvk1-1.obis.ns.nl",
            "switch2": "switch-mBvk1-2.obis.ns.nl",
            "switch3": "switch-abv5-1.obis.ns.nl"
            }

switches_dns2 = {
            "switch3": "switch-abv5-1.obis.ns.nl",
            "switch1": "switch-mBvk1-1.obis.ns.nl",
            "switch2": "switch-mBvk1-2.obis.ns.nl"          
            }

switches_dns3 = {
            "switch2": "switch-mBvk1-2.obis.ns.nl",
            "switch3": "switch-abv5-1.obis.ns.nl",
            "switch1": "switch-mBvk1-1.obis.ns.nl"                      
            }

switches_dns4 = {
            "switch2": "switch-abv5-1.obis.ns.nl",
            "switch3": "switch-mBvk1-2.obis.ns.nl",
            "switch1": "switch-mBvk1-1.obis.ns.nl"                      
            }

print("====> Testcase 1")   
for switch, hostname_dns in  switches_dns1.items():
    print(switch)
    try:
        snmp_session = easysnmp.Session(hostname=hostname_dns, security_username='test_user', auth_protocol='MD5', auth_password='blahblahblah', version=3, security_level='auth_with_privacy', privacy_password='blahblahblah', privacy_protocol='DES')
        result=snmp_session.get('.1.3.6.1.4.1.37072.302.3.1.1.3.6.0')
        print("Switch: {}, Result: {}".format(switch, result))
    except easysnmp.exceptions.EasySNMPTimeoutError as err:
        print("Switch: {}, result: TIMEOUT ERROR".format(switch))

When running this script for all for dictionaries, the only thing changing being the order of the switches queried I'm getting these results:

====> Testcase 1 switch1 Switch: switch1, Result: <SNMPVariable value='10.160.59.131' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch2 Switch: switch2, Result: <SNMPVariable value='10.160.59.132' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch3 Switch: switch3, result: TIMEOUT ERROR [root@tesu john.roede]# python3 test2.py

====> Testcase 2 switch3 Switch: switch3, Result: <SNMPVariable value='10.160.59.133' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch1 Switch: switch1, result: TIMEOUT ERROR switch2 Switch: switch2, Result: <SNMPVariable value='10.160.59.132' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> [root@tesu john.roede]# python3 test2.py

====> Testcase 3 switch2 Switch: switch2, Result: <SNMPVariable value='10.160.59.132' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch3 Switch: switch3, result: TIMEOUT ERROR switch1 Switch: switch1, result: TIMEOUT ERROR [root@tesu john.roede]# python3 test2.py

====> Testcase 4 switch2 Switch: switch2, Result: <SNMPVariable value='10.160.59.133' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch3 Switch: switch3, Result: <SNMPVariable value='10.160.59.132' (oid='enterprises.37072.302.3.1.1.3.6.0', oid_index='', snmp_type='IPADDR')> switch1 Switch: switch1, result: TIMEOUT ERROR

As you can see, every switch does respond at times, so there shouldn't be an issue at the switch level. Just to be 100% sure I've also written a quick bash script querying all 3 switches in succession. This does work:

./test.sh
SNMPv2-SMI::enterprises.37072.302.3.1.1.3.6.0 = IpAddress: 10.160.59.131
SNMPv2-SMI::enterprises.37072.302.3.1.1.3.6.0 = IpAddress: 10.160.59.132
SNMPv2-SMI::enterprises.37072.302.3.1.1.3.6.0 = IpAddress: 10.160.59.133

I really can't figure out what's causing the issue with easysnmp. I've tried separating the several SNMP calls with a sleep to rule out I'm firing of the calls in too quick a succession, but this didn't solve the issue. I've also looked in the easysnmp documentation for a Session.close() function but there doesn't seem to be one. There is mention of a update_session() function which I haven't tried since the documentation states: "While it is recommended to create a new Session instance instead, this method has been added for your convenience in case you really need it (we’ve mis-typed the community string before in our interactive sessions and totally understand your pain)."

I'd really appreciate some help with this issue and would like to thank you for your time in advance.

PS. Apologies, I can't seem to get the formatting of the output right :-(

7th Sin
  • 11
  • 3

1 Answers1

0

I've been digging a bit deeper and it turns out this issue is caused by several devices using the same engine ID.

See https://github.com/easysnmp/easysnmp/issues/156 for more information.

7th Sin
  • 11
  • 3