diff --git a/mackerel-plugin-snmp/lib/snmp.go b/mackerel-plugin-snmp/lib/snmp.go index 8df2f694b..326ff4560 100644 --- a/mackerel-plugin-snmp/lib/snmp.go +++ b/mackerel-plugin-snmp/lib/snmp.go @@ -52,8 +52,17 @@ func (m SNMPPlugin) FetchMetrics() (map[string]interface{}, error) { ret, err := strconv.ParseFloat(fmt.Sprint(resp.Variables[0].Value), 64) if err != nil { - log.Println(err) - continue + // NOTE: Cannot assume strconv.ParseFloat("%s", resp.Variables[0].Value) + // first, as resp.Variables[0].Value may be an int class, etc. + // Normally, an object values such as INTEGER or Counter are + // successfully accepted in the above conversions. + // However, STRING object values are passed as byte arrays, so the above + // conversion will result in an error. + ret, err = strconv.ParseFloat(fmt.Sprintf("%s", resp.Variables[0].Value), 64) + if err != nil { + log.Println(err) + continue + } } stat[sm.Metrics.Name] = ret diff --git a/mackerel-plugin-snmp/rule.txt b/mackerel-plugin-snmp/rule.txt index 247e6b2a4..8c83ff471 100644 --- a/mackerel-plugin-snmp/rule.txt +++ b/mackerel-plugin-snmp/rule.txt @@ -1,2 +1,3 @@ snmp.hrSystemNumUsers >=0 snmp.hrSystemProcesses >=0 +snmp.echo >0 diff --git a/mackerel-plugin-snmp/test.sh b/mackerel-plugin-snmp/test.sh index 6062a129b..22f3ec5cb 100755 --- a/mackerel-plugin-snmp/test.sh +++ b/mackerel-plugin-snmp/test.sh @@ -26,7 +26,7 @@ docker run --name "test-$plugin" -v $(pwd)/testdata/snmpd.conf:/etc/snmp/snmpd.c trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15 sleep 10 -$plugin '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' | graphite-metric-test -f rule.txt +$plugin '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' '.1.3.6.1.4.1.8072.1.3.2.3.1.2.4.101.99.104.111:echo:0:0' | graphite-metric-test -f rule.txt status=$? docker stop "test-$plugin" diff --git a/mackerel-plugin-snmp/testdata/snmpd.conf b/mackerel-plugin-snmp/testdata/snmpd.conf index 9238dc279..4dbf6298d 100644 --- a/mackerel-plugin-snmp/testdata/snmpd.conf +++ b/mackerel-plugin-snmp/testdata/snmpd.conf @@ -1,4 +1,7 @@ -view systemonly included .1.3.6.1.2.1.1 -view systemonly included .1.3.6.1.2.1.25.1 - -rocommunity public default -V systemonly +view systemonly included .1.3.6.1.2.1.1 +view systemonly included .1.3.6.1.2.1.25.1 +view systemonly included .1.3.6.1.4.1.8072.1.3.2.3.1.2.4 + +rocommunity public default -V systemonly + +extend echo /bin/echo '3.14'