0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
scriptOmate
  • 57
  • 1
  • 2
  • 7

2 Answers2

1

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)
)
Pooh
  • 244
  • 1
  • 2
  • Looking at pysnmp source, I'm starting to think that valid syntax for varbinds part is: ((MIB, symbol), value). That is (('abc-mib', 'abcRowStatus'), 4). Modern way is to use MibVariable: [link]http://pysnmp.sourceforge.net/examples/current/v3arch/oneliner/manager/setgen.html – Pooh Nov 07 '12 at 22:10
  • That didn't work. I got a 'split' exception. I tried (cmdgen.MibVariable('abc-mib', symbol), 4) as in the example, but then I get an error saying that abc-mib.py is not in the search path, even though getvar works fine. I was also trying figure out how to cast the value like I did for scalars: rfc1902.Unsigned32(4), but RowStatus is not in rfc1902 or any other proto module I have found. Of course, the definition is on SNMPv2-TC.py. – scriptOmate Nov 07 '12 at 22:44
  • abc-mib.py must be in MIB search path to work unless it's put into pysnmp/smi/mibs/ directory. Use MibVariable('abc-mib', symbol).addMibSource('/path') to give it alternative path. That's interesting how getvar works without that. Another thing is that you should be able to use just rfc1902.Integer(4) as value on CommandGenerator side. RowStatus is its derivative and its specifics is only important on CommandResponder side. – Pooh Nov 08 '12 at 06:39
0

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.

scriptOmate
  • 57
  • 1
  • 2
  • 7