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

OctetString conversion to String #46

Closed
vbob opened this issue Mar 9, 2019 · 1 comment
Closed

OctetString conversion to String #46

vbob opened this issue Mar 9, 2019 · 1 comment

Comments

@vbob
Copy link

vbob commented Mar 9, 2019

I want to do a generic SNMP Subtree, but I am having problems with OctetString conversion:

  • MAC Adresses are decoded with .toString('hex')
  • Text is decoded with .toString('utf8')

My code is the following:

this.connection.subtree(oid, (varbinds: Array<any>) => {
  varbinds.forEach(varbind => {
    if (snmp.isVarbindError(varbind))
      message.push({
        'oid': varbind.oid,
        'value': snmp.varbindError(varbind)
      })

    else {
      if (varbind['type'])
        varbind['type'] = snmp.ObjectType[varbind['type']]

      // How to make this statement generic?
      if (varbind['value'] instanceof Buffer)
        varbind['value'] = varbind['value'].toString("hex")

      message.push(varbind)
    }
  })
})

And my responses are:

[{
    oid: "1.3.6.1.2.1.2.2.1.2.2",
    type: "OctetString",
    value: "526564204861742c20496e63204465766963652030303031"
},
// [...]
{
    oid: "1.3.6.1.2.1.2.2.1.6.2",
    type: "OctetString",
    value: "82f8c67920e6"
}]

The expected snmpget responses are:

1.3.6.1.2.1.2.2.1.2.2 = STRING: Red Hat, Inc Device 0001
1.3.6.1.2.1.2.2.1.6.2 = STRING: 82:f8:c6:79:20:e6

How can I distinguish one from the other and create a generic subtree function with correct string conversion?

@stephenwvickers
Copy link
Collaborator

You will need to know the data type you are dealing with if they are both instances of OctetString.

If you can load the MIB file somehow, then you can use that to determine how to parse OctetString instances.

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

No branches or pull requests

2 participants