0
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from pysnmp.entity.rfc3413.oneliner import cmdgen
def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx):
    print varBinds

def main():
    ip = '127.0.0.1'
    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBinds = cmdGen.nextCmd(
        cmdgen.CommunityData('mymypub')
        cmdgen.UdpTransportTarget((ip, 161)),
        '1.3.6.1.2.1.17.7.1.2.2.1.2')
    #varBinds have about 200 elements
    print varBinds

    cmdGen = cmdgen.AsynCommandGenerator()
    cmdGen.asyncNextCmd(
        cmdgen.CommunityData('mymypub'),
        cmdgen.UdpTransportTarget((ip, 161)),
        ((1,3,6,1,2,1,17,7,1,2,2,1,2),),
        (cbFun, ip))
    cmdGen.snmpEngine.transportDispatcher.runDispatcher()
    #varBinds have 1 element
if __name__ == '__main__':
    main()

I get all elements in CommandGenerator. But i have only one element in AsynCommandGenerator. How i can get all of them?

kalombo
  • 861
  • 1
  • 9
  • 31

1 Answers1

1

To perform another GETNEXT, cbFun() should request that by returning True. Otherwise no next GETNEXT will be performed by AsynCommandGenerator.

See relevant example

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
  • i've added "return True" and i've got a different values between CommandGenerator and AsynCommandGenerator. Count of async values is huge. Also i have tried your example and still have got a huge package of values. – kalombo Jan 30 '13 at 04:30
  • Sync version, by default, stops once "next" OID leaves the initial OID prefix. This can be changed by adding lexicographicMode=True parameter. Async version always walks Agent till end-of-mib unless your cbFun() stops it earlier. I'm not sure what is your ultimate goal here. Please, advise. – Ilya Etingof Jan 31 '13 at 15:57
  • This is a sync version fetching the whole MIB (if maxRows is removed): http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/manager/cmdgen/getnext-v3-pull-whole-mib-with-options.html – Ilya Etingof Jan 31 '13 at 15:59