Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EasySNMP Walk/BulkWalk
#1
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.
Reply
#2
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
Reply
#3
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())
Reply
#4
i solved this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Smile Python & MSGraph - Learning to Walk ITMan020324 2 423 Feb-04-2024, 04:37 PM
Last Post: ITMan020324
Question Cannot import easysnmp: ImportError: libnetsnmp.so.30 Calab 4 1,057 Jun-08-2023, 08:52 PM
Last Post: Gribouillis
  How to sort os.walk list? Denial 6 11,581 Oct-10-2020, 05:28 AM
Last Post: Denial
  os.walk question DPaul 2 2,346 May-31-2020, 02:08 PM
Last Post: DPaul
  os.walk(Path("path_string")) giving error Kumarkv 4 3,882 May-10-2020, 08:46 AM
Last Post: snippsat
  os.walk does not see files that are in the folder kiton 1 3,030 Jan-21-2020, 07:26 PM
Last Post: micseydel
  print notifcation when enter new directory os.walk() evilcode1 3 2,630 Jun-20-2019, 08:19 PM
Last Post: evilcode1
  Animating Random Walk Excelsiscelia 2 5,227 Nov-24-2018, 08:53 AM
Last Post: Excelsiscelia
  Python3 & os.walk while_e_coyote 2 3,452 Aug-24-2018, 07:32 PM
Last Post: while_e_coyote
  easysnmp output printing help anna 0 2,818 Apr-03-2018, 09:19 AM
Last Post: anna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020