Skip to content

Commit

Permalink
Fix string to int64 conversion for SNMP input (#7407)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdrayton authored Apr 24, 2020
1 parent 8957032 commit 1bb436e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugins/inputs/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ func fieldConvert(conv string, v interface{}) (interface{}, error) {
case uint64:
v = int64(vt)
case []byte:
v, _ = strconv.Atoi(string(vt))
v, _ = strconv.ParseInt(string(vt), 10, 64)
case string:
v, _ = strconv.Atoi(vt)
v, _ = strconv.ParseInt(vt, 10, 64)
}
return v, nil
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ func TestFieldConvert(t *testing.T) {
{uint64(123), "float(3)", float64(0.123)},
{"123", "int", int64(123)},
{[]byte("123"), "int", int64(123)},
{"123123123123", "int", int64(123123123123)},
{[]byte("123123123123"), "int", int64(123123123123)},
{float32(12.3), "int", int64(12)},
{float64(12.3), "int", int64(12)},
{int(123), "int", int64(123)},
Expand Down

0 comments on commit 1bb436e

Please sign in to comment.