snmp: support table indexes as tags (#2366)
This commit is contained in:
committed by
Daniel Nelson
parent
1402c158b7
commit
995546e7c6
@@ -168,6 +168,9 @@ type Table struct {
|
||||
// Which tags to inherit from the top-level config.
|
||||
InheritTags []string
|
||||
|
||||
// Adds each row's table index as a tag.
|
||||
IndexAsTag bool
|
||||
|
||||
// Fields is the tags and values to look up.
|
||||
Fields []Field `toml:"field"`
|
||||
|
||||
@@ -464,13 +467,19 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
|
||||
}
|
||||
}
|
||||
|
||||
for i, v := range ifv {
|
||||
rtr, ok := rows[i]
|
||||
for idx, v := range ifv {
|
||||
rtr, ok := rows[idx]
|
||||
if !ok {
|
||||
rtr = RTableRow{}
|
||||
rtr.Tags = map[string]string{}
|
||||
rtr.Fields = map[string]interface{}{}
|
||||
rows[i] = rtr
|
||||
rows[idx] = rtr
|
||||
}
|
||||
if t.IndexAsTag && idx != "" {
|
||||
if idx[0] == '.' {
|
||||
idx = idx[1:]
|
||||
}
|
||||
rtr.Tags["index"] = idx
|
||||
}
|
||||
// don't add an empty string
|
||||
if vs, ok := v.(string); !ok || vs != "" {
|
||||
|
||||
Reference in New Issue
Block a user