Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Different encoding of results #41

Closed
stuarthannig opened this issue Feb 8, 2021 · 2 comments · Fixed by #46
Closed

Different encoding of results #41

stuarthannig opened this issue Feb 8, 2021 · 2 comments · Fixed by #46

Comments

@stuarthannig
Copy link

Using gem 'netsnmp', '~> 0.3.0'

Is this an issue with xor? I installed xorcist, but same results.

This is the request/results from the snmpwalk command on CLI:

$ snmpwalk -v 3 <auth> <ip address> 1.3.6.1.4.1.1991.1.1.3.33.1.1.1.4

iso.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.8.76.65.71.45.77.65.84.72 = Hex-STRING: 00 00 00 06 00 00 00 07 00 00 0C 8C
iso.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.14.76.65.71.45.84.72.69.45.84.72.73.78.71.83 = Hex-STRING: 00 00 00 0A 00 00 00 0B 00 00 0C 0A
iso.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.14.76.65.71.45.84.72.69.83.69.45.65.76.83.79 = Hex-STRING: 00 00 00 10 00 00 00 11 00 00 0C 88

This is the results from this gem, converted to hash from the Enumarato (for readability):

=> {
  "1.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.8.76.65.71.45.77.65.84.72"=>
  "00 00 00 06 00 00 00 07 00 00 0C 8C",
 "1.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.14.76.65.71.45.84.72.69.45.84.72.73.78.71.83"=>
  "\u0000\u0000\u0000\n\u0000\u0000\u0000\v\u0000\u0000\f\n",
 "1.3.6.1.4.1.1991.1.1.3.33.1.1.1.4.14.76.65.71.45.84.72.69.83.69.45.65.76.83.79"=>
  "00 00 00 10 00 00 00 11 00 00 0C 88"
  }

The first and last values are <Encoding:US-ASCII>, but the second value is <Encoding:UTF-8>. Is it possible to force the encoding to the ASCII encoding? As we can see from the returned values, ASCII matches the results from the CLI.

Having two different encodings requires a conditional to handle the results separately.

@HoneyryderChuck
Copy link
Collaborator

Hi @stuarthannig thank you for the report.

I think it might have smth to do with this: https://github.com/swisscom/ruby-netsnmp/blob/master/lib/netsnmp/varbind.rb#L51

My question here would be, how could you distinguish between the string and hex string, if not using this admittedly naive approach?

I'd suggest you set a breakpoint here and check what causes the middle value to be convertible, and how else could you identify it as an hex string

@HoneyryderChuck
Copy link
Collaborator

https://stackoverflow.com/questions/35439244/how-to-convert-the-hex-value-that-i-receive-from-snmp for reference.

The netsnmp cli tool uses MIB information about the OID to know how to parse it.

Given that now there's a MIB parser, one could take advantage of this.

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

Successfully merging a pull request may close this issue.

2 participants