Skip to content

Commit

Permalink
fix: table test init test reworked
Browse files Browse the repository at this point in the history
  • Loading branch information
MyaLongmire committed Oct 11, 2021
1 parent aedc233 commit 42fc07e
Show file tree
Hide file tree
Showing 3 changed files with 2,608 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ type snmpTableCache struct {
func snmpTable(oid string) (mibName string, oidNum string, oidText string, fields []Field, err error) {
var stc snmpTableCache
stc.mibName, stc.oidNum, stc.oidText, stc.fields, stc.err = snmpTableCall(oid)
println(stc.fields)
return stc.mibName, stc.oidNum, stc.oidText, stc.fields, stc.err
}

Expand Down Expand Up @@ -819,6 +818,7 @@ func snmpTableCall(oid string) (mibName string, oidNum string, oidText string, f
// grabs all columns from the table
// mimmicks grabbing everything returned from snmptable -Ch -Cl -c public 127.0.0.1 oidFullName
col := node.GetRow().AsTable().ColumnOrder

for i := range col {
_, isTag := tagOids[mibPrefix+col[i]]
fields = append(fields, Field{Name: col[i], Oid: mibPrefix + col[i], IsTag: isTag})
Expand Down
13 changes: 8 additions & 5 deletions plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ func TestTableInit(t *testing.T) {
require.NoError(t, err)

tbl := Table{
Oid: ".1.0.0.0",
Oid: ".1.3.6.1.2.1.3.1",
Fields: []Field{
{Oid: "TEST::description", Name: "description", IsTag: true},
{Oid: ".1.3.6.1.2.1.3.1.1.1", Name: "atIfIndex"},
{Oid: "RFC1213-MIB::atPhysAddress", Name: "atPhysAddress", IsTag: true},
},
}
s := &Snmp{
Expand All @@ -161,10 +162,12 @@ func TestTableInit(t *testing.T) {
err = tbl.Init(s)
require.NoError(t, err)

assert.Equal(t, "testTable", tbl.Name)
assert.Equal(t, "atTable", tbl.Name)

assert.Len(t, tbl.Fields, 1)
assert.Contains(t, tbl.Fields, Field{Oid: ".1.0.0.0.1.4", Name: "description", IsTag: true, initialized: true, snmp: s})
assert.Len(t, tbl.Fields, 4)
assert.Contains(t, tbl.Fields, Field{Oid: ".1.3.6.1.2.1.3.1.1.1", Name: "atIfIndex", initialized: true, snmp: s})
assert.Contains(t, tbl.Fields, Field{Oid: ".1.3.6.1.2.1.3.1.1.2", Name: "atPhysAddress", IsTag: true, initialized: true, snmp: s, Conversion: "hwaddr"})
assert.Contains(t, tbl.Fields, Field{Oid: ".1.3.6.1.2.1.3.1.1.3", Name: "atNetAddress", initialized: true, IsTag: true, snmp: s})
}

func TestSnmpInit(t *testing.T) {
Expand Down
Loading

0 comments on commit 42fc07e

Please sign in to comment.