keith_k

String returned by NSA snmp.getnumber() function

Discussion created by keith_k on Aug 11, 2009
Latest reply on Aug 12, 2009 by carstein.seeberg
The snmp.walk() function returns a table of values for the OIDs that were received in response to the SNMP query.  I wrote a loop to print all of the values in the table, and the loop contains this line:
print(k.." : "..k1.." : "..k2.." ("..type(v2).."): '"..v2.."'")
The table returned by one walk contains these OIDs (amongst others):
oids : 7 : type (string): 'INTEGER'
oids : 7 : ucd (string): '.iso.3.6.1.4.1.789.1.21.1.2.1.2.8'
oids : 7 : oid (string): '.1.3.6.1.4.1.789.1.21.1.2.1.2.8'
oids : 7 : value (string): '3'
oids : 7 : variable (string): '3'
oids : 7 : itype (number): '2'
Then I use the snmp.getnumber() function to extract the value of this same OID and print the result:
value = snmp.getnumber(result, oid.."."..i)
print(oid.."."..i.." : "..name.." ("..type(value).."): '"..value.."'"
This is what is printed:
.1.3.6.1.4.1.789.1.21.1.2.1.2.8 : enclContactState (string): '3'
For some reason, the function returns a string value instead of a number.  I can convert it to a number with the tonumber() fucntion, but I suspect I should not need to do that.  Any thoughts?

Thanks,
Keith

Outcomes