From 1bb436e8a8df3d34cfac569dfa8a21aadb7ae4fb Mon Sep 17 00:00:00 2001 From: Mark Drayton Date: Fri, 24 Apr 2020 22:35:59 +0200 Subject: [PATCH] Fix string to int64 conversion for SNMP input (#7407) --- plugins/inputs/snmp/snmp.go | 4 ++-- plugins/inputs/snmp/snmp_test.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index 2fc56ff97..2f8bf6d5b 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -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 } diff --git a/plugins/inputs/snmp/snmp_test.go b/plugins/inputs/snmp/snmp_test.go index 25382bd7d..d29b525ad 100644 --- a/plugins/inputs/snmp/snmp_test.go +++ b/plugins/inputs/snmp/snmp_test.go @@ -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)},