Add snmp input option to strip non fixed length index suffixes (#4025)

This commit is contained in:
Matt
2018-04-17 20:34:39 -04:00
committed by Daniel Nelson
parent 058510464c
commit 9ef902f4a1
3 changed files with 24 additions and 0 deletions

View File

@@ -237,6 +237,8 @@ type Field struct {
Oid string
// OidIndexSuffix is the trailing sub-identifier on a table record OID that will be stripped off to get the record's index.
OidIndexSuffix string
// OidIndexLength specifies the length of the index in OID path segments. It can be used to remove sub-identifiers that vary in content or length.
OidIndexLength int
// IsTag controls whether this OID is output as a tag or a value.
IsTag bool
// Conversion controls any type conversion that is done on the value.
@@ -462,6 +464,18 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
}
idx = idx[:len(idx)-len(f.OidIndexSuffix)]
}
if f.OidIndexLength != 0 {
i := f.OidIndexLength + 1 // leading separator
idx = strings.Map(func(r rune) rune {
if r == '.' {
i -= 1
}
if i < 1 {
return -1
}
return r
}, idx)
}
fv, err := fieldConvert(f.Conversion, ent.Value)
if err != nil {