Reputation: 430
I am trying to walk the sysORTable using the bulkget commandgenerator using the following code based from the samples:
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.bulkCmd(
cmdgen.UsmUserData(user,
authKey=authKey,
privKey=privKey,
authProtocol=authProto,
privProtocol=privProto,
securityEngineId=None
),
cmdgen.UdpTransportTarget((sHost, 161)),
0 , 25,
*[cmdgen.MibVariable(oid) for oid in sOID] )
However the results returned from the agent are over the 255 character limit imposed by the MIB lookup. I have found two workarounds to this problem:
DisplayString
in pysnmp/smi/mibs/SNMPv2-TC.py: subtypeSpec = OctetString.subtypeSpec + ValueSizeConstraint(0, 512)
lookupMib=False
However both these fixes, while allowing the script to complete, seem to truncate the output. For example:
[ObjectType(ObjectIdentity(<ObjectName value object at 0x7f1c04686cd0 tagSet <TagSet object at 0x7f1c0c88dad0 tags 0:0:6> payload [1.3.6.1.2.1.1.9.1.3.106]>), <DisplayString value object at 0x7f1c04623150 subtypeSpec <ConstraintsIntersection object at 0x7f1c04a64490 consts <ValueSizeConstraint object at 0x7f1c0756c510 consts 0, 65535>, <ValueSizeConstraint object at 0x7f1c04a64450 consts 0, 512>> tagSet <TagSet object at 0x7f1c0c88d5d0 tags 0:0:4> encoding iso-8859-1 payload [Agent capabiliti...B
File name: sys]>)]
Note the ellipsis and the line break.
Two questions:
Upvotes: 0
Views: 623
Reputation: 5555
First of, this seems like a bug in your SNMP agent - they should not overflow the string. In that sense pysnmp is doing just fine. ;-)
To answer your questions:
repr()
, it won't happen if you do str
or .prettyPrint()
on the value:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
The example can be found here.
Upvotes: 1