Skip to content

Commit

Permalink
add STRING number support
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Mar 28, 2024
1 parent 99db858 commit c2f0178
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions mackerel-plugin-snmp/lib/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ 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
ret, err = strconv.ParseFloat(fmt.Sprintf("%s", resp.Variables[0].Value), 64)
if err != nil {
log.Println(err)
continue
}
}

stat[sm.Metrics.Name] = ret
Expand Down
1 change: 1 addition & 0 deletions mackerel-plugin-snmp/rule.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
snmp.hrSystemNumUsers >=0
snmp.hrSystemProcesses >=0
snmp.echo >0
2 changes: 1 addition & 1 deletion mackerel-plugin-snmp/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions mackerel-plugin-snmp/testdata/snmpd.conf
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit c2f0178

Please sign in to comment.