質問

I want to get all information about a select list of interfaces. Currently I have a variable oid_base

oid_base = ['1.3.6.1.2.1.2.2.1.1.', 
            '1.3.6.1.2.1.2.2.1.2.', 
            '1.3.6.1.2.1.2.2.1.3.', 
            ...,
            '1.3.6.1.2.1.2.2.1.22.']

and a list of interfaces (I want to query about 20 out of hundreds)

interfaces = ['35', '37', '94']

To get the data I want, I'm looping through the interfaces and creating an oid_args for each interface that I pass to cmdgen.getCmd individually:

for interface in snmpif.interfaces():
  oid_args = [str(b + interface) for b in oid_base]
  ei, es, ein, var_binds = cmd_gen.getCmd(sec_obj, trans, *oid_args)
  # Handle errors and output of `var_binds`

Is there a way of querying all the interfaces in bulk and getting back a table.

I have tried playing with cmdgen.bulkCmd but I can't figure out how to select the interfaces.

役に立ちましたか?

解決

Assuming you are trying to optimise for the number of SNMP communications, you could use getBulk() but for pools of adjacent interfaces. For instance if you have to query interfaces 2,3,4 you could do getBulk() for interface 1 wight the maxRepetitions and maxRows parameters set to 3 (the number of interfaces to query).

Those 'isolated' interfaces could be queried individually by putting them at the beginning of oid_args and setting getBulk's nonRepeaters option accordingly.

Regardless of SNMP request type, you could stuff as many OIDs into the request as SNMP packet could accommodate, not necessarily only those belonging to a single interface.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top