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

SNMP plugin HEX STRING conversion #3478

Closed
Heksyl opened this issue Nov 16, 2017 · 10 comments · Fixed by #15439
Closed

SNMP plugin HEX STRING conversion #3478

Heksyl opened this issue Nov 16, 2017 · 10 comments · Fixed by #15439

Comments

@Heksyl
Copy link

Heksyl commented Nov 16, 2017

Feature Request

Opening a feature request kicks off a discussion.

Proposal:

I would like to read and convert snmp HEX(octet) STRING values to something more readable.

Current behavior:

HEX(octet) STRINGS are not translated, not even read correctly

Desired behavior:

HEX(octet) STRINGS are translated to STRING, INT or FLOAT.

Use case: [Why is this important (helps with prioritizing requests)]

For example i have HP server related mib, which contains:

        SYNTAX  OCTET STRING (SIZE (6))
        ACCESS  read-only
        STATUS  mandatory
        DESCRIPTION
            "The time stamp when the event log entry was first created.

             field  octets  contents                  range
             =====  ======  ========                  =====
               1      1-2   year                      0..65536
               2       3    month                     1..12
               3       4    day                       1..31
               4       5    hour                      0..23
               5       6    minute                    0..59

            The year field is set with the most significant octet first.
            A value of 0 in the year indicates an unknown time stamp."
        ::= { cpqHeEventLogEntry 6 }

I would like to get those values in any readable form. Right now i get something like:

----                              ----------
1510751525000000000               ���  ```
@phemmer
Copy link
Contributor

phemmer commented Nov 16, 2017

This is a really, really, obscure (and bad IMHO) way of encoding a date/time into a value.
I think there are 3 options.

  1. Use hwaddr converter. This format happens to have 6 bytes, which is the same as a hardware (MAC) address. However this will format the time 2017-11-16T09:04 as 14:11:0b:10:09:04.
  2. Add a converter for this specific method of encoding a date (no idea what we'd call it), and either translate it into a string, or epoch integer.
  3. Some sort of generic binary to string conversion. E.G. [20,17,11,16,09,04] ([0x14,0x11,0x0b,0x10,0x09,0x04]) to the string "14 11 0b 10 09 04" (similar to hwaddr, but for arbitrary length).

@danielnelson thoughts?

@danielnelson
Copy link
Contributor

I think we probably can't add a converter for this date since it is such a custom format, the best we can probably do is have a general purpose converter for binary to hex string.

@thechristschn
Copy link

I think I found another usecase for OCTET STRING to INT conversion.

I want to collect interface metrics of a fibre channel switch, which are stored inside connUnitPortStatTable (1.3.6.1.3.94.4.5) in the FCMGMT-MIB.

For example connUnitPortStatCountTxObjects counts transmitted objects, but the output is an OCTET STRING. With conversion INT, output is currently always 0.

connUnitPortStatCountTxObjects OBJECT-TYPE 
    SYNTAX OCTET STRING (SIZE (8))
    ACCESS read-only 
    STATUS mandatory 
    DESCRIPTION 
        "The number of frames/packets/IOs/etc that have been transmitted
        by this port. Note: A Fibre Channel frame starts with SOF and
        ends with EOF. FC loop devices should not count frames passed
        through. This value represents the sum total for all other Tx
        objects."
    ::= { connUnitPortStatEntry 4 }

@phemmer
Copy link
Contributor

phemmer commented Jan 4, 2018

@thechristschn That's not the same as what this issue is about. For your case see the documentation on the conversion parameter: https://github.com/influxdata/telegraf/tree/release-1.5/plugins/inputs/snmp#field-parameters

@thechristschn
Copy link

@phemmer ok, then I'm sorry.
I thought the desired behavior in this request was what i meant. (At least the part when translating to INT)

Desired behavior:
HEX(octet) STRINGS are translated to STRING, INT or FLOAT.

So I guess I should open a bug, that in my case HEX STRINGS aren't converted to meaningful integers if conversion is set to INT?

@phemmer
Copy link
Contributor

phemmer commented Jan 4, 2018

An octet string isn't a "hex string". Hex encoding is a method of representing an octet string, useful when the string contains binary data. This request was to perform hex encoding for such binary data. Your OID you pasted sounds like you want conversion = "int" added to your config.

@pmagos00
Copy link

@pmagos00
Copy link

For this issue .. tested whit

#!/bin/ksh
snmpwalk -v1 -c public X.X.X.X  .1.3.6.1.3.94.4.5.1.4 | while read output;
do
index=`echo $output | cut -d "." -f 23| cut -d "=" -f 1| tr -d " \t\r"`
to_convert=`echo $output | cut -d ":" -f 4| tr -d " \t\r"`;
echo brocade,agent_host=X.X.X.X,connUnitPortStatIndex=$index,host=host   connUnitPortStatCountTxObjects=$(( 16#$to_convert ))
done

The magic is in: $(( 16#$to_convert ))

@cesarmacias
Copy link

Hi,

Its necessary to have another type of conversion, when the value are hex string like this example:

SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.0 = Hex-STRING: 48 57 54 43 33 D9 B4 12
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.1 = Hex-STRING: 48 57 54 43 33 DC 70 12
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.2 = Hex-STRING: 48 57 54 43 33 E9 B8 12
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.3 = Hex-STRING: 48 57 54 43 33 EE 89 12
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.4 = Hex-STRING: 48 57 54 43 33 EC 24 12
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.43.1.3.4194312192.5 = Hex-STRING: 48 57 54 43 33 DA F4 12

In this example the return are Serial Number, one solution is transform in string but like hwaddr with more bytes, example:
Hex-STRING: 48 57 54 43 33 DA F4 12 -> "4857544333daf412"

@MyaLongmire
Copy link
Contributor

I am going to close this as snmptraslate is deprecated in telegraf and supported versions no longer use it due to performance issues and this ticket hasn't been active in a few years. If you are having issues with the recent snmp update, please open another ticket with all relevant information.

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

Successfully merging a pull request may close this issue.

8 participants