Frage

I have tried various things according to the documentation, but I cannot figure out how set the MIB in a dynamic table. I have code that sets scalar values and works fine. I know that I have to set a value of createAndGo(4) on the RowStatus and then set it to active(1). Here is what I tried and the MIB definition:

    abcTable = MibTable((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4))
    abcEntry = MibTableRow((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1)).setIndexNames((0, "abc-mib", "abcEntryNum"))
    abcRowStatus = MibTableColumn((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 1),        RowStatus()).setMaxAccess("readcreate")
    abcEntryNum = MibTableColumn((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 2), Integer32().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 10))).setMaxAccess("noaccess")
    abcName = MibTableColumn((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 3), DisplayString().subtype(subtypeSpec=constraint.ValueSizeConstraint(0, 30))).setMaxAccess("readcreate")
    abcType = MibTableColumn((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 4), Integer().subtype(subtypeSpec=constraint.SingleValueConstraint(0,2,3,1,)).subtype(namedValues=namedval.NamedValues(("aa", 0), ("ab", 1), ("cb", 2), ("ca", 3), )).clone(0)).setMaxAccess("readcreate")
    abcLocation = MibTableColumn((1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 5), Integer32().subtype(subtypeSpec=constraint.ValueRangeConstraint(-1800, 1800))).setMaxAccess("readcreate")

    def getvar(self, symbol):
        """Used to get the dot notation string from the symbol in the MIB"""
        varObj, = self.mibBuilder.importSymbols('abc-mib', symbol)
        return varObj.getName()

    # Create the first Row
    errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd( \
        self.authData,
        cmdgen.UdpTransportTarget((host_addr, 161)),
        (getvar('abcRowStatus') + (1,), 4)  )

I get the following error:

Message File Name Line Position Traceback
set_single abc.py
setCmd build\bdist.win32\egg\pysnmp\entity\rfc3413\oneliner\cmdgen.py 374
setCmd build\bdist.win32\egg\pysnmp\entity\rfc3413\oneliner\cmdgen.py 240
AttributeError: MibIdentifier instance has no attribute 'getSyntax'

Any ideas?

War es hilfreich?

Lösung 2

It seems that @pooh is right in that the type is the issue. I used the getvar function as is but just added the correct type (rfc1902.Integer(4)) and it works. I think you can also use the MibVariable('abc-mib, 'abcRowStatus', 1).addMibSource(/path) but I did not try this. The table index is a bit confusing, that is why I stuck with the getvar + (1,) which indexes into the table. I believe for looking at other examples that the I believe the way to use MibVariable in a multi-level table is MibVariable('abc-mib, 'abcRowStatus', '1.2.3') where '1.2.3' is the index into the multi-level column element.

Andere Tipps

You seem to refer to a MIB object identified by OID "abcRowStatus" + 1. That is

(1, 3, 6, 1, 4, 1, 6367, 3, 21, 4, 1, 1,  1)

Is that object really defined in your MIB?

Since you do not specify SNMP type of the value (passing a Python integer), for setCmd() to build a proper request message, it must cast pure Python type (integer in your code) into SNMP type. To figure out SNMP type it looks up MIB object named "abcRowStatus", takes its OID and appends a '1' sub-OID as you requested. Then it looks up MIB object by that OID and if found takes SNMP type associated with it for further casting.

So, I suppose your code should read like:

cmdgen.CommandGenerator().setCmd(
    self.authData,
    cmdgen.UdpTransportTarget((host_addr, 161)),
    (getvar('abcRowStatus'), 4)
)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top