-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 Trap input does not properly handle non-string data #9113
Comments
Hi, thanks for the issue. To clarify my understanding, if a field is going to be given a value that contains invalid characters, is the request that the field is dropped in this instance? Or another form of sanitization? |
I guess sanitize would be good. Perhaps this is something that would fit best in a processor, giving the option to sanitize inputs via a processor before they are sent to the output plugin. Go has a |
I agree that a processor would make a lot of sense, there is currently a Not sure if it would work at all, but there is a |
Ok I've submitted a PR to add an option to the strings processor to sanitize strings using Go's ToValidUTF8 function: #9118 |
This issue is based on an incorrect assumption. Let's look at the OID in question jnxCmRescueChgDate OBJECT-TYPE
SYNTAX DateAndTime
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The date and time when the rescue configuration was last
changed."
::= { jnxCmRescueChg 2 }
DateAndTime ::= TEXTUAL-CONVENTION
DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
STATUS current
DESCRIPTION
"A date-time specification.
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 minutes 0..59
6 7 seconds 0..60
(use 60 for leap-second)
7 8 deci-seconds 0..9
8 9 direction from UTC '+' / '-'
9 10 hours from UTC* 0..13
10 11 minutes from UTC 0..59
* Notes:
- the value of year is in network-byte order
- daylight saving time in New Zealand is +13
For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be
displayed as:
1992-5-26,13:30:15.0,-4:0
Note that if only local time is known, then timezone
information (fields 8-10) is not present."
SYNTAX OCTET STRING (SIZE (8 | 11)) You can see here that this field is not a "string" at all, rather an array of bytes that encodes a representation of a timestamp. For example the first two bytes, in network-byte order, are not two ASCII or UTF-8 characters, they are a 16-bit integer that represents the year. This brings us to the incorrect assumption. While the syntax (or type) The real issue here isn't figuring out how to print things that are non-printable. It is that Telegraf's SNMP Trap input doesn't properly handle |
@robcowart yes you are totally correct, I've updated the issue title and description (pointing to your explanation). In my case, it's still useful for the time being to just sanitize the whole thing as utf-8, because the system I'm sending the data to (Grafana Loki) fails to parse anything if any part of any message in a search isn't utf-8. However, a proper solution would involve parsing this type of data into readable text. |
For the time being, You could opt to drop that specific field from the measurement, so you can use it with Grafana and Loki. |
Closing since linked PR got merged |
#9118 doesn't actually fix this issue. It just makes it possible to pass along mishandled data. |
Okay, could you clarify what is still missing then? |
I already did that above... #9113 (comment) |
If you are not going to handle the data properly, at least don't destroy it by replacing non-printable characters with junk. It would be better to transform the raw byte slice into a printable form using something like |
Where do those non-printable characters get replaced? I'm willing to add functionality to transform bytes to hex encoding, but It's difficult to find out when to do it and when not. I don't think it is always the case when SYNTAX is |
any update on this? we still cannot decode SystemClock fields from snmp traps from standard routers like Cisco Juniper |
Hi, we were running into the same issue, in this case jnxCmCfgChgLatestDate (1.3.6.1.4.1.2636.3.18.1.3.0), which is also an SNMP DateAndTime object. Using snmpwalk we got:
We are using the json serializer which gave us:
Comparing the two outputs, somehow the first two bytes
We now worked around the issue by base64 encoding the value using
to:
and base64 decoding the value in our application. |
Looking at this case from the point of view of the json_test.go in the repo, I observed the following The JSON serialiser prepares to handle all incoming data through Later, the Golang json.Marshal is called to actually serialise that data, but as that code follows this principle
the 0xe8 becomes Unicode So unless these byte array timestamps are desired to be unpacked inside telegraf into their textual representation, the byte array content should be passed through as-is without attempting char conversion of the bytes, just dump the bytes with |
System info:
1.18.1 running in docker
Steps to reproduce:
When using the snmp_trap input plugin, some devices send traps with non utf-8 encoded strings, for instance:
Expected behavior:
See #9113 (comment)
Actual behavior:
See #9113 (comment)
Additional info:
The text was updated successfully, but these errors were encountered: