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

add STRING number support #1166

Merged
merged 2 commits into from
Apr 1, 2024
Merged

add STRING number support #1166

merged 2 commits into from
Apr 1, 2024

Conversation

kmuto
Copy link
Member

@kmuto kmuto commented Mar 29, 2024

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 by fmt.Sprintf('%s' only if the parsing failed first. resp.Variables[0].Value may be vary, so original first fmt.Sprint(resp.Variables[0].Value) works well, except a byte array of string.
  • To test it, extend command is added. It will back STRING 3.14. .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:

2024/03/29 08:47:18 strconv.ParseFloat: parsing "[51 46 49 52]": invalid syntax
graphite-metric-test: <stdin>: rule snmp.echo[>0] is not matched any metrics
test-mackerel-plugin-snmp
test-mackerel-plugin-snmp

After:

test-mackerel-plugin-snmp
test-mackerel-plugin-snmp

@kmuto kmuto merged commit 76fb736 into mackerelio:master Apr 1, 2024
13 checks passed
@kmuto kmuto deleted the snmpd-stringvalue branch April 1, 2024 01:57
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

Successfully merging this pull request may close these issues.

2 participants