Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found mackerel-plugin-snmp failed to parse a number of STRING type from SNMP device, like
strconv.ParseFloat: parsing "[51 46 49 52]": invalid syntax
.For example, original value from SNMP device is '3.14', and
51 46 49 52
seems the byte array of '3.14'.Because it is usually impossible to change a type on the SNMP device side, the receiver has a responsiblity to accept it.
Here is a patch to support STRING number.
parseFloat
again for byte array with forcing String conversion byfmt.Sprintf('%s'
only if the parsing failed first.resp.Variables[0].Value
may be vary, so original firstfmt.Sprint(resp.Variables[0].Value)
works well, except a byte array of string..1.3.6.1.4.1.8072.1.3.2.3.1.2.4.101.99.104.111 = STRING: 3.14
Result of test.sh
Before:
After: