Re: [pysnmp-users] Using a different asyncsock poll
Brought to you by:
elie
From: Ilya E. <il...@gl...> - 2013-10-07 21:52:39
|
Hi Craig, >> You could either AsynsockDispatcher.getSocketMap() to use pysnmp's >> socket map for zmq or AsynsockDispatcher.setSocketMap() zmq's socket >> map to pysnmp. > I couldn't get it to work. The line I was using was > cmdGen.snmpEngine.transportDispatcher.setSocketMap(zmq_core.socket_map) > If I do it just after cmdGen is created then transportDispatcher is > None, so can't be there. > After the first cmdGet line i don't get an error but it doesn't do > anything either. The following code seems to configure foreign socket map to pysnmp dispatcher/transports: ------------- from pysnmp.entity import engine from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher sharedSocketMap = {} transportDispatcher = AsynsockDispatcher() transportDispatcher.setSocketMap(sharedSocketMap) snmpEngine = engine.SnmpEngine() snmpEngine.registerTransportDispatcher(transportDispatcher) cmdGen = cmdgen.CommandGenerator(snmpEngine = snmpEngine) errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( cmdgen.CommunityData('public', mpModel=0), cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0) ) ------------- >> What exactly is the ID you we are talking about? Is it RequestID >> from SNMP message structure? Or it's sendRequestHandle passed to >> response processing callback? Please, clarify. > If you have some code like > my_id = cmdGen.bulkCmd(....) > def cbFun(sendRequestHandle, .... > > If it is all a single packet, then my_id will equal sendRequestHandle > otherwise it will be the last packet ID. Assuming you are using AsynCommandGenerator class, its design is as follows - each bulkCmd() call schedules an SNMP message to be sent and returns an ID. Once a matching response message arrives (or times out), user callback is invoked with the same ID passed in first argument. You could schedule and send many SNMP messages at once through bulkCmd(), each will get its own ID. There's actually no correlation between individual request messages, only between request and response. So if you are sending many request messages in parallel, you should store all their IDs and handle responses for each of those IDs. >> If you pass both ifTable and ipAdEntAddr in request, pysnmp will >> track each of the columns individually and stop when both columns >> are fetched. If columns are of different length pysnmp will fetch >> extra OIDs past the shorter column to preserve "rectangular" table >> in response. > To me it looks like the system will keep fetching until the callback > returns False. Remember this is the async dispatcher. The test seems > to be isPrefixOf() or, strangely varBindHead <= name in the example. > If everything is the same table then all is good because all entries > finish at the same time. Oh, right. I meant its synchronous version (e.g. CommandGenerator). For async version your callback is to stop command generator once all data it is interested in is received. Since GETNEXT/GETBULK commands always fetch ordered OIDs, the isPrefixOf or OIDs comparison operations could reveal whether received OID belongs to a certain OIDs tree branch. Other checks are indeed possible. > However if you have a device with 5 interfaces and 2 ip addresses then > the checker will hit whatever is next after the ip address on the third > row and terminate there. That's right. It's up to your callback to handle that case if it is not desirable. -ilya |