Advertisement
Guest User

pysnmp mass async command generator

a guest
Oct 23rd, 2013
2,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. from pysnmp.entity.rfc3413.oneliner import cmdgen
  2.  
  3. # add your hosts here
  4. #targets = [ '127.0.0.1', '127.0.0.2' ]
  5. targets = ['127.0.0.1']*1000
  6.  
  7. def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex,
  8.           varBinds, cbCtx):
  9.     if errorIndication:
  10.         print(errorIndication)
  11.         return 1
  12.     if errorStatus:
  13.         print('%s at %s' % (
  14.             errorStatus.prettyPrint(),
  15.             errorIndex and varBinds[int(errorIndex)-1] or '?'
  16.             )
  17.         )
  18.         return 1
  19.  
  20.     for oid, val in varBinds:
  21.         if val is None:
  22.             print(oid.prettyPrint())
  23.         else:
  24.             print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
  25.  
  26. cmdGen  = cmdgen.AsynCommandGenerator()
  27.  
  28. for transportTarget in targets:
  29.     cmdGen.getCmd(
  30.         cmdgen.CommunityData('public'),
  31.         cmdgen.UdpTransportTarget((transportTarget, 161)),
  32.         ( '1.3.6.1.2.1.1.1.0', ),
  33.         # User-space callback function and its context
  34.         (cbFun, None)
  35.     )
  36.  
  37. cmdGen.snmpEngine.transportDispatcher.runDispatcher()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement