Reuse getCmd object in pysnmp

2024/10/15 17:14:46

In the pysnmp documentation there is a getCmd class, I was wondering if it was possible to just instantiate the class once and reuse it at a later point by passing it new oids. I am not sure if the getCmd class exposes methods to allow me to change the oids.

http://pysnmp.sourceforge.net/docs/hlapi/asyncore/sync/manager/cmdgen/getcmd.html

Answer

The getCmd name is referring to a function, not a class. Technically, it is a generator, but that is not important here.

It is cheap to call *Cmd() because all the heavy lifting and state management is done on the SnmpEngine object (first argument to getCmd). Thus it is important, from performance standpoint, to keep SnmpEngine object as persistent as possible.

>>> from pysnmp.hlapi.asyncore import *
>>> snmpEngine = SnmpEngine()
>>> for oid in ['1.3.6.1.2.1.2.2.1.8.1', '1.3.6.1.2.1.2.2.1.8.2']:
...     g = getCmd(snmpEngine,
...                CommunityData('public'),
...                UdpTransportTarget(('demo.snmplabs.com', 161)),
...                ContextData(),
...                ObjectType(ObjectIdentity(oid)))
>>>     print(next(g))
https://en.xdnf.cn/q/117809.html

Related Q&A

Django plugged into Apache not working like Django standalone

I have encountered a hodgepodge of errors trying to bring my django site into production with Apache. Having finally gotten mod_wsgi sorted and Apache at least seeming to be trying to load the site Im …

How to filter overlap rows in a big file in python

I am trying to filter overlap rows in a big file in python.The overlap degrees is set to 25%. In other words,the number of element of intersection between any two rows is less than 0.25 times of union …

Installing wxPython in Ubuntu 12.10

I am trying to install wxPython on my Ubuntu 12.10 but with no success. I have gone through all the answers given on this website. Can someone please help me in this or point me in the right direction.…

Open a file name +date as csv in Python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

TextCtrl providing an out of bound exception in wxPython

I am new to WX, so I decided to make a program that will periodically write out a line of text to the screen based on an outside input. The basis of the program contains a basic window with the multili…

Matplotlib: different color for every point of line plot

Im trying to make a plot like in the following figure (source of image): Im talking about the plot in the right panel even though there is some correlation between the two panels: the colorbar. Just s…

getting template syntax error in django template

my code in view :tracks = client.get(/tracks, order=hotness, limit=4) artwork_url=[] for track in tracks:artwork_url.append(str(track.artwork_url).replace("large", "t300x300")) …

Python threading:Is it okay to read/write multiple mutually exclusive parts of a file concurrently?

I know we can guarantee correctness either by locking or using a specialized thread whose sole job is to read/write and communicate with it through queue. But this approach seems logically ok, so I wan…

Theano Cost Function, TypeError: Unknown parameter type: class numpy.ndarray

Im new to Theano, just learning it. I have a ANN in python that Im implementing in Theano as learning process. Im using Spyder.And Theano throws out an error: TypeError: Unknown parameter type: class n…

Bar plotting grouped Pandas

I have a question regarding plotting grouped DataFrame data.The data looks like:data =index taste food0 good cheese 1 bad tomato 2 worse tomato 3 worse …