Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

way to get opaque data ? #35

Open
cmpetty opened this issue Nov 12, 2015 · 3 comments
Open

way to get opaque data ? #35

cmpetty opened this issue Nov 12, 2015 · 3 comments
Labels

Comments

@cmpetty
Copy link

cmpetty commented Nov 12, 2015

is there a way to get/set opaque values?

For instance here's a few snippets from calling the snmp command line tools:

snmptranslate -On -Td WIENER-CRATE-MIB::outputVoltage
.1.3.6.1.4.1.19947.1.3.2.1.10
outputVoltage OBJECT-TYPE
  -- FROM   WIENER-CRATE-MIB
  -- TEXTUAL CONVENTION Float
  SYNTAX    Opaque (WIENER-CRATE-MIB) 
  UNITS     "V"
  MAX-ACCESS    read-write
  STATUS    current
  DESCRIPTION   "The nominal output voltage of the channel."

Pull the value:

snmpget -v 2c -m +WIENER-CRATE-MIB -c public localhost outputVoltage.u0
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V

Set the value as a float:

snmpset -v 2c -m +WIENER-CRATE-MIB -c higher localhost outputVoltage.u0 F 8
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V

When i try to do the same thing via python and easysnmp, i get a "wrongEncoding" error if i try float.

And if i do a walk snmp_type is empty, along with all the values:

session.walk('WIENER-CRATE-MIB::outputVoltage')
Out[29]:
SNMPVariable value='' (oid='outputVoltage', oid_index='1', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='2', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='3', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='4', snmp_type='')

Even though i know they are set from the command line version of walk:

snmpwalk -v 2c -m +WIENER-CRATE-MIB -c public localhost outputVoltage
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u1 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u2 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u3 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u4 = Opaque: Float: 8.000000 V

I had to assume this is from the Opaque part of the data because i can get/set INTEGERS normally:

In [30]: session.set('WIENER-CRATE-MIB::outputSwitch.1','0',snmp_type='i')
Out[30]: True
In [31]: session.get('WIENER-CRATE-MIB::outputSwitch.1')
Out[31]: <SNMPVariable value='0' (oid='outputSwitch', oid_index='1', snmp_type='INTEGER')>

Any help is appreciated because this seems the logical way of moving forward rather than reaching out to snmpset with subprocess. Thanks.

@fgimian fgimian added the bug label Mar 9, 2016
@samibrahiem
Copy link

samibrahiem commented Aug 18, 2016

I am facing the same problem, when I try getting Opaque type OID, I only get the tag. The rest of the values (iid,val and type) are set to "None". Is there a way to read these OIDs through EasySNMP?

@cmpetty
Copy link
Author

cmpetty commented Aug 18, 2016

i never found a way through easysnmp to get/set opaques.

i used pysnmp to get them, but then had to covert them .. here's a sample:

from pysnmp.entity.rfc3413.oneliner import cmdgen 

cmdGen = cmdgen.CommandGenerator()
     cmdgen.UdpTransportTarget((crateip, 161)),
                                                                            '1.3.6.1.4.1.19947.1.3.2.1.12', #outputCurrent
                                                                            '1.3.6.1.4.1.19947.1.3.2.1.10', #outputVoltage
                                                                            '1.3.6.1.4.1.19947.1.3.2.1.7', #outputMeasurementCurrent
                                                                            )

        currdata = []
        currtime = time.time()

        for var in varBinds:
            for sv in var:
                oidsplit = sv[0].getOid().prettyPrint().split('.')
                chanidx = oidsplit[-1]
                oid_noidx = '.'.join(oidsplit[:-1])
                name = mibLUT[oid_noidx]

                if re.search('opaque',sv[-1].prettyPrintType(),re.IGNORECASE):
                    outval = struct.unpack('>f',sv[-1].asOctets()[3:])[0]
                else:
                    outval = sv[-1]._value
                currdata.append([currtime, name, outval, chanidx ])

        thisdf = pd.DataFrame(currdata,columns=['measurementTime','measurementType','measurementValue','channel'])

@samibrahiem
Copy link

Thank you for sharing Chris! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants