diff --git a/pkg/collector/corechecks/snmp/internal/session/session.go b/pkg/collector/corechecks/snmp/internal/session/session.go index a2e46a7ea0839..e6db9c7d5b9e6 100644 --- a/pkg/collector/corechecks/snmp/internal/session/session.go +++ b/pkg/collector/corechecks/snmp/internal/session/session.go @@ -212,7 +212,7 @@ func FetchAllFirstRowOIDsVariables(session Session) []gosnmp.SnmpPDU { } else { nextColumn, err := GetNextColumnOidNaive(oid) if err != nil { - log.Debugf("Invalid column oid: %s", oid) + log.Debugf("Invalid column oid %s: %s", oid, err) curRequestOid = oid // fallback on continuing by using the response oid as next oid to request } else { curRequestOid = nextColumn diff --git a/pkg/collector/corechecks/snmp/internal/session/utils.go b/pkg/collector/corechecks/snmp/internal/session/utils.go index e646948ee6f03..98b96b00961b3 100644 --- a/pkg/collector/corechecks/snmp/internal/session/utils.go +++ b/pkg/collector/corechecks/snmp/internal/session/utils.go @@ -24,9 +24,13 @@ 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) + idx = strings.LastIndex(tableOid+".", ".1.") // Try to find the table Entry OID + if idx == -1 { + // not found + return "", fmt.Errorf("the oid is not a column oid: %s", oid) + } + tableOid = oid[0:idx] + rowFullIndex = oid[idx+3:] // +3 to skip `.1.` } rowFirstIndex := strings.Split(rowFullIndex, ".")[0] rowFirstIndexNum, err := strconv.Atoi(rowFirstIndex) diff --git a/pkg/collector/corechecks/snmp/internal/session/utils_test.go b/pkg/collector/corechecks/snmp/internal/session/utils_test.go index 289be0ad97d3d..e2d0055c09b20 100644 --- a/pkg/collector/corechecks/snmp/internal/session/utils_test.go +++ b/pkg/collector/corechecks/snmp/internal/session/utils_test.go @@ -35,11 +35,11 @@ func TestGetNextColumnOid(t *testing.T) { }, { 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", + expectedOid: "1.3.6.1.2.1.2.2.1.2", }, { 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", + expectedErr: "the oid is not a column oid: 1.3.6.2.2.2.2.2.1.9", }, } for _, tt := range tests {