python - PySNMP returning different values on different machines -
a script developed on laptop runs fine there, on remote server isn't returning i'd expect.
my server has output:
python 2.7.5 (default, jun 17 2014, 18:11:42) [gcc 4.8.2 20140120 (red hat 4.8.2-16)] on linux2 type "help", "copyright", "credits" or "license" more information. >>> import pysnmp >>> print pysnmp.__version__ 4.2.5 >>> >>> pysnmp.entity.rfc3413.oneliner import cmdgen >>> cmdgen = cmdgen.commandgenerator() >>> >>> errorindication, errorstatus, errorindex, varbindtable = cmdgen.nextcmd( ... cmdgen.communitydata('communitystringhere'), ... cmdgen.udptransporttarget(('10.10.10.10', 161)), ... '1.3.6.1.2.1.2.2.1.2', ... lookupnames=true, lookupvalues=true) >>> ... varbindtablerow in varbindtable: ... val in varbindtablerow: ... print val ... (mibvariable(objectname(1.3.6.1.2.1.2.2.1.2.1)), octetstring('fxp0')) (mibvariable(objectname(1.3.6.1.2.1.2.2.1.2.4)), octetstring('lsi')) (mibvariable(objectname(1.3.6.1.2.1.2.2.1.2.5)), octetstring('dsc')) (mibvariable(objectname(1.3.6.1.2.1.2.2.1.2.6)), octetstring('lo0')) [output truncated...]
the results mibvariable , octetstring.
on laptop, following:
python 2.7.10 (default, feb 7 2017, 00:08:15) [gcc 4.2.1 compatible apple llvm 8.0.0 (clang-800.0.34)] on darwin type "help", "copyright", "credits" or "license" more information. >>> import pysnmp >>> print pysnmp.__version__ 4.3.2 >>> >>> pysnmp.entity.rfc3413.oneliner import cmdgen >>> [code ommitted, same above...] ... snmpv2-smi::mib-2.2.2.1.2.1 = fxp0 snmpv2-smi::mib-2.2.2.1.2.4 = lsi snmpv2-smi::mib-2.2.2.1.2.5 = dsc snmpv2-smi::mib-2.2.2.1.2.6 = lo0 [output truncated...]
i'm not sure making pysnmp return differently, other minor version - older version (on server) seems have nicer output 'newer' version on laptop?
am missing obvious?
you right, default str
representation of mibvariable
object (or objecttype
in later pysnmp versions) changed between minor pysnmp versions...
can call .prettyprint()
on varbind
? produce uniform representation across different pysnmp versions:
for varbindtablerow in varbindtable: varbind in varbindtablerow: print(varbind.prettyprint())
as matter of hack, can mimic old str
representation this:
... >>> varbind = varbinds[0] >>> name, value = varbind >>> '%s(%s(%s), %s(%s))' % ( type(varbind).__name__, type(name).__name__, name, type(value).__name__, value ) 'objecttype(objectidentity(1.3.6.1.2.1.1.1.0), displaystring(linux zeus 4.8.6.5-smp #2 smp sun nov 13 14:58:11 cdt 2016 i686))'
Comments
Post a Comment