snmp: Allow lines with empty or missing tags (#2172)
The changes in #1848 resulted in lines being dropped if they had an empty tag. Let's allow all lines that have empty or missing tags!
This commit is contained in:
parent
d4d3f61673
commit
b0c721491d
|
@ -433,10 +433,8 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
|||
if err != nil {
|
||||
return nil, Errorf(err, "converting %q (OID %s) for field %s", ent.Value, ent.Name, f.Name)
|
||||
}
|
||||
if fvs, ok := fv.(string); !ok || fvs != "" {
|
||||
ifv[""] = fv
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err := gs.Walk(oid, func(ent gosnmp.SnmpPDU) error {
|
||||
if len(ent.Name) <= len(oid) || ent.Name[:len(oid)+1] != oid+"." {
|
||||
|
@ -456,9 +454,7 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
|||
if err != nil {
|
||||
return Errorf(err, "converting %q (OID %s) for field %s", ent.Value, ent.Name, f.Name)
|
||||
}
|
||||
if fvs, ok := fv.(string); !ok || fvs != "" {
|
||||
ifv[idx] = fv
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -476,8 +472,10 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
|||
rtr.Fields = map[string]interface{}{}
|
||||
rows[i] = rtr
|
||||
}
|
||||
// don't add an empty string
|
||||
if vs, ok := v.(string); !ok || vs != "" {
|
||||
if f.IsTag {
|
||||
if vs, ok := v.(string); ok {
|
||||
if ok {
|
||||
rtr.Tags[f.Name] = vs
|
||||
} else {
|
||||
rtr.Tags[f.Name] = fmt.Sprintf("%v", v)
|
||||
|
@ -487,6 +485,7 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt := RTable{
|
||||
Name: t.Name,
|
||||
|
@ -494,10 +493,6 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
|||
Rows: make([]RTableRow, 0, len(rows)),
|
||||
}
|
||||
for _, r := range rows {
|
||||
if len(r.Tags) < tagCount {
|
||||
// don't add rows which are missing tags, as without tags you can't filter
|
||||
continue
|
||||
}
|
||||
rt.Rows = append(rt.Rows, r)
|
||||
}
|
||||
return &rt, nil
|
||||
|
|
|
@ -457,9 +457,24 @@ func TestTableBuild_walk(t *testing.T) {
|
|||
"myfield4": 22,
|
||||
},
|
||||
}
|
||||
assert.Len(t, tb.Rows, 2)
|
||||
rtr3 := RTableRow{
|
||||
Tags: map[string]string{},
|
||||
Fields: map[string]interface{}{
|
||||
"myfield2": 0,
|
||||
"myfield3": float64(0.0),
|
||||
},
|
||||
}
|
||||
rtr4 := RTableRow{
|
||||
Tags: map[string]string{},
|
||||
Fields: map[string]interface{}{
|
||||
"myfield3": float64(9.999),
|
||||
},
|
||||
}
|
||||
assert.Len(t, tb.Rows, 4)
|
||||
assert.Contains(t, tb.Rows, rtr1)
|
||||
assert.Contains(t, tb.Rows, rtr2)
|
||||
assert.Contains(t, tb.Rows, rtr3)
|
||||
assert.Contains(t, tb.Rows, rtr4)
|
||||
}
|
||||
|
||||
func TestTableBuild_noWalk(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue