Skip to content

Commit

Permalink
improve GetNextColumnOidNaive
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang committed Nov 24, 2023
1 parent 04dd1bd commit 86f5326
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkg/collector/corechecks/snmp/internal/session/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions pkg/collector/corechecks/snmp/internal/session/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit 86f5326

Please sign in to comment.