diff --git a/pkg/collector/corechecks/snmp/internal/session/utils.go b/pkg/collector/corechecks/snmp/internal/session/utils.go index c02be8eaea65ce..e646948ee6f039 100644 --- a/pkg/collector/corechecks/snmp/internal/session/utils.go +++ b/pkg/collector/corechecks/snmp/internal/session/utils.go @@ -23,6 +23,11 @@ func GetNextColumnOidNaive(oid string) (string, error) { } tableOid := oid[0:idx] rowFullIndex := oid[idx+3:] // +3 to skip `.1.` + if !strings.Contains(rowFullIndex, ".") { + // TODO: test me + // entry `.1.` must be followed by a column + index, hence the index is expected to contain at least one `.` + return "", fmt.Errorf("the last `.1.` is not an table entry: %s", oid) + } rowFirstIndex := strings.Split(rowFullIndex, ".")[0] rowFirstIndexNum, err := strconv.Atoi(rowFirstIndex) if err != nil { diff --git a/pkg/collector/corechecks/snmp/internal/session/utils_test.go b/pkg/collector/corechecks/snmp/internal/session/utils_test.go index 610b422cb849c3..289be0ad97d3d7 100644 --- a/pkg/collector/corechecks/snmp/internal/session/utils_test.go +++ b/pkg/collector/corechecks/snmp/internal/session/utils_test.go @@ -25,12 +25,6 @@ func TestGetNextColumnOid(t *testing.T) { oid: "1.3.6.1.2.1.2.2.1.99.99", expectedOid: "1.3.6.1.2.1.2.2.1.100", }, - { - oid: "1.3.6.1.2.1.2.2.1.1.1", - // ideally it should return "1.3.6.1.2.1.2.2.1.2" instead of `1.3.6.1.2.1.2.2.1.1.2` - // but we can improve the algorithm later if needed - expectedOid: "1.3.6.1.2.1.2.2.1.1.2", - }, { oid: "1.3.6.2.2.2.2.2.99999", expectedErr: "the oid is not a column oid: 1.3.6.2.2.2.2.2.99999", @@ -39,6 +33,14 @@ func TestGetNextColumnOid(t *testing.T) { oid: ".1.3.6.1.2.1.2.2.1.2.99.", // trim trailing/ending `.` expectedOid: "1.3.6.1.2.1.2.2.1.3", }, + { + oid: "1.3.6.1.2.1.2.2.1.1.1", + expectedErr: "the last `.1.` is not an table entry: 1.3.6.1.2.1.2.2.1.1.1", + }, + { + oid: "1.3.6.2.2.2.2.2.1.9", + expectedErr: "the last `.1.` is not an table entry: 1.3.6.2.2.2.2.2.1.9", + }, } for _, tt := range tests { t.Run(tt.oid, func(t *testing.T) {