hi...

am using pysnmp module to do an snmp get on a USB key status

from pysnmp.entity.rfc3413.oneliner import cmdgen

#--query on ccmSDIDUKeyStatus
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxx', 'xxx', 1), cmdgen.UdpTransportTarget(('192.168.5.157', 161)), (1,3,6,1,4,1,18489,1,2,4,2,8,0))

varBinds gives the following:

[(ObjectName('1.3.6.1.4.1.18489.1.2.4.2.8.0'), Integer('2'))]

I need to print the key status, based on varBinds, it is connected if Integer('1'), disconnected if Integer('2')

I have read that, varBinds is a 'tuple of managed objects' and 'each managed object is a pair of Object Name and Object Value'.

By this, I understand that, my varBinds gives me 1 managed object(name,value pair)


I need to access this 'value' from varBinds

how can I do it??

any help is welcome

Recommended Answers

All 2 Replies

If there is only 1 pair, you should get the value with

value = varBinds[0][1]

This value's type is probably this Integer class http://twistedsnmp.sourceforge.net/pydoc/pysnmp.asn1.univ.html#Integer or a similar class. Since the class has an __int__ method, you should be able to convert it directly to a python int:

n = int(value)

If there is only 1 pair, you should get the value with

value = varBinds[0][1]

This value's type is probably this Integer class http://twistedsnmp.sourceforge.net/pydoc/pysnmp.asn1.univ.html#Integer or a similar class. Since the class has an __int__ method, you should be able to convert it directly to a python int:

n = int(value)

thanks a lot...:) it helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.