Python Forum
EasySNMP Walk/BulkWalk - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: EasySNMP Walk/BulkWalk (/thread-35558.html)



EasySNMP Walk/BulkWalk - pylance - Nov-17-2021

Hello,
1st post for me, new to python.. very new..
I am working on a project and need a little help.
I am only getting 1 results with any of the commands in easysnmp.
Not the sub oids that I get in a commandline or mib broswer.

I run this code, and I left some of the testing methods commented out trying to different methods.
from easysnmp import Session
import time,
start = time.time()
ap450 = 'PMP 450'
ap450i = 'PMP 450i'
ap450m = 'PMP 450m'

def test(host):
    start = time.time()                      
    session = Session(hostname=host, community='public', version=2)   
    print('start')
    productTypeName = session.get('.1.3.6.1.4.1.161.19.3.3.1.266.0')
    aptype = productTypeName.value
    print(aptype)
    if aptype == ap450m:
        print('found 450M')
        #
        whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0') 
        print(whispBridgeMacAddr.value)
        dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
#        dump_ap = session.walk('oid')
        for item in dump_ap:
            with open('ap_dump/' + '450m_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
                sm_dump.writelines("%s\n" % l for l in [item.value]) 
                #print([item.value])
                break
    elif aptype == ap450i:
        print ('found 450i')
        #
        with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
            for oid in oids:
                whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0') 
                print(whispBridgeMacAddr.value)
        dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
#        dump_ap = session.walk('oid')
                for item in dump_ap:
                    with open('ap_dump/' + '450i_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
                        sm_dump.writelines("%s\n" % l for l in [item.value]) 
                        #print([item.value])
                        break
    elif aptype == ap450:
        print('found 450')
        #
        with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
            for oid in oids:
                whispBridgeMacAddr = session.get('.1.3.6.1.4.1.161.19.3.3.1.3.0') 
                print(whispBridgeMacAddr.value)
        dump_ap = session.bulkwalk('.1.3.6.1.4.1.161.19.3.1.4.1.69',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.bulkwalk('oid',non_repeaters=0, max_repetitions=10)
#        dump_ap = session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
#        dump_ap = session.walk('oid')
                for item in dump_ap:
                    with open('ap_dump/' + '450_' + '%s.txt' % whispBridgeMacAddr.value, 'a') as sm_dump:
                        sm_dump.writelines("%s\n" % l for l in [item.value]) 
                        #print([item.value])
                        break
    else:
        print('no aps found')
    
    print('It took', time.time()-start, 'seconds.')   
    print('end')         

def init_test1():
    with open('apips.txt', 'r') as ips:	    
                for ip in ips:        
                    test(ip.strip())
        #with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:
        #   for oid in oids:
init_test1()
Commandline output
snmpwalk -v 2c -c public 10.32.229.14 .1.3.6.1.4.1.161.19.3.1.4.1.69
iso.3.6.1.4.1.161.19.3.1.4.1.69.2 = IpAddress: 10.32.167.101
iso.3.6.1.4.1.161.19.3.1.4.1.69.3 = IpAddress: 10.32.166.128
iso.3.6.1.4.1.161.19.3.1.4.1.69.4 = IpAddress: 10.32.167.79
iso.3.6.1.4.1.161.19.3.1.4.1.69.5 = IpAddress: 10.32.167.115
iso.3.6.1.4.1.161.19.3.1.4.1.69.7 = IpAddress: 10.32.166.53
iso.3.6.1.4.1.161.19.3.1.4.1.69.8 = IpAddress: 10.32.166.166
iso.3.6.1.4.1.161.19.3.1.4.1.69.9 = IpAddress: 10.32.167.192
on the surface it appears the code works, until I look at the file.
start
PMP 450m
found 450M
0a-00-3e-60-c5-d6
It took 2.4697763919830322 seconds.
end
start
PMP 450i
found 450i
0a-00-3e-bb-50-2b
It took 1.848592758178711 seconds.
end
start
PMP 450
found 450
0a-00-3e-b2-c1-62
It took 1.206430196762085 seconds.
end
Thanks for any help.


RE: EasySNMP Walk/BulkWalk - pylance - Nov-17-2021

I have tested this with .get and it pulls the same info, if I use .walk with a single ip and oid.. I get the correct info.
When passing ips or oids from a list is where the system seems to break..
any feed back apperciated


RE: EasySNMP Walk/BulkWalk - pylance - Nov-17-2021

I solved the issue above..
however I believe it to be a little messy with the connection.
I am creating a new connection to run each walk command, I cant seem to think of a way to run all of the OID's during 1 session with this..
Also the output is not as desired atm, but am working on that.
initial function, added argument
def test(host,oid):
passing new arguments
def init_test5():  
    with open('apips.txt', 'r') as ips:	   
        for x in ips:
            with open ('bulkwalk/' + '450_bulkwalk_sm_stats.txt', 'r') as oids:                
                for y in oids:                      
                    test(x.strip(), y.strip())



RE: EasySNMP Walk/BulkWalk - pylance - Nov-29-2021

i solved this.