1

I was wondering if anyone has any ideas on what i'm goofing up. Essentially i am trying to fetch the entire mac table from a cisco switch using snmpv3. Apparently cisco sucks and you need to query each vlan individually unlike other vendors ... So my question is, How would i go about implementing that in pysnmp? I tried a few ways and they keep coming up with errors. Right now my working bulk command below works, but for the mac tables i need to figure out how to specify a vlan number which is where i'm having the most issues. Any help is appreciated.

The equivalent snmpv2c command is 
snmpwalk -v2c -c letsconfigRO@10 10.0.0.101 1.3.6.1.2.1.17.4.3.1.1


My current iteration of a bulk command for pysnmp is 

auth = cmdgen.UsmUserData(userName=snmpv3Username,
                                  authKey=snmpv3Password,
                                  authProtocol=authProtocol,
                                  privKey=privKey,
                                  privProtocol=privProtocol)

        errorIndication, errorStatus, errorIndex, varBinds = cmdGen.bulkCmd(
            auth,
            cmdgen.UdpTransportTarget((host, 161)),
            0, 1000,
            cmdgen.MibVariable(walk_oid),
            lookupMib=False,
            lexicographicMode=False
        )

which works fine for normal walking as it does fetch the mac table, but only for vlan 1. 


One of the latest ones i tried after this was 

# Create SNMP engine instance
    snmp_engine = SnmpEngine()

    # Create SNMPv3 user data object
    user = UsmUserData(userName=snmpv3Username,
                        authKey=snmpv3Password,
                        authProtocol=authProtocol,
                        privKey=privKey,
                        privProtocol=privProtocol)
    # Define SNMPv3 target
    target = UdpTransportTarget(('10.0.0.101', 161))

    # Define VLAN ID
    vlan_id = 10

    # Define OID for retrieving MAC addresses for a specific VLAN
    oid = ObjectType(ObjectIdentity('BRIDGE-MIB', 'dot1dTpFdbPort'))

    # Define OID for retrieving VLAN membership information
    vmVlan_oid = ObjectType(ObjectIdentity('CISCO-VLAN-MEMBERSHIP-MIB', 'vmVlan', vlan_id))

    # Perform bulkwalk operation to retrieve the MAC address table
    iterator = bulkCmd(
        snmp_engine,
        user,
        target,
        ContextData(),
        oid,
        lexicographicMode=False,
        maxRepetitions=500,
        acInfo=(vmVlan_oid, None)
    )

But for some reason that throws the following error. 
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'ObjectType'
Lex Li
  • 60,503
  • 9
  • 116
  • 147
Rob
  • 153
  • 1
  • 3
  • 14

1 Answers1

1

Ok, in case someone has a road block like me. I love when i figure out what i did wrong AFTER asking questions ... I had the wrong order in the requests. I had to inspect the backend / docs to see what order it was expecting items to be passed. This works below

    # Define VLAN ID
    vlan_id = 10

    # Define OID for retrieving MAC addresses for a specific VLAN
    oid = ObjectType(ObjectIdentity('BRIDGE-MIB', 'dot1dTpFdbPort'))

    # Define OID for retrieving VLAN membership information
    vmVlan_oid = ObjectType(ObjectIdentity('CISCO-VLAN-MEMBERSHIP-MIB', 'vmVlan', vlan_id))

    iterator = bulkCmd(
        snmp_engine,
        user,
        target,
        ContextData(contextName='vlan-' + str(vlan_id)),
        0, 500,
        oid,
        lexicographicMode=False,
        acInfo=(vmVlan_oid, None)
        )
Rob
  • 153
  • 1
  • 3
  • 14
  • While it might help Cisco device users, it does indicate a very Cisco specific tip (to set context name), which does not apply to other vendors. Thanks for sharing and I added cisco tag to the question. – Lex Li Mar 11 '23 at 05:37
  • Next question i'm having issues with now. Any one have any idea how to translate this to snmpv2? – Rob Mar 17 '23 at 19:19