Skip to content

Commit

Permalink
Allow keeping of old labels from lookups.
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Brazil <[email protected]>
  • Loading branch information
brian-brazil committed Sep 25, 2018
1 parent cbeddc8 commit f4998bc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
3 changes: 2 additions & 1 deletion generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ modules:
# Required if context is configured on the device.

lookups: # Optional list of lookups to perform.
# This must only be used when the new index is unique.
# If keep_old is the default of false, this must only be used when the new index is unique.

# If the index of a table is bsnDot11EssIndex, usually that'd be the label
# on the resulting metrics from that table. Instead, use the index to
# lookup the bsnDot11EssSsid table entry and create a bsnDot11EssSsid label
# with that value.
- old_indexes: [bsnDot11EssIndex]
new_index: bsnDot11EssSsid
keep_old: false # If true, don't delete old index label for this lookup.

overrides: # Allows for per-module overrides of bits of MIBs
metricName:
Expand Down
1 change: 1 addition & 0 deletions generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ type ModuleConfig struct {
type Lookup struct {
OldIndexes []string `yaml:"old_indexes"`
NewIndex string `yaml:"new_index"`
KeepOld bool `yaml:"keep_old,omitempty"`
}
6 changes: 4 additions & 2 deletions generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
} else {
needToWalk[indexNode.Oid] = struct{}{}
}
// Avoid leaving the old labelname around.
toDelete = append(toDelete, lookup.OldIndexes...)
if !lookup.KeepOld {
// Avoid leaving the old labelname around.
toDelete = append(toDelete, lookup.OldIndexes...)
}
}
}
for _, l := range toDelete {
Expand Down
48 changes: 48 additions & 0 deletions generator/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,54 @@ func TestGenerateConfigModule(t *testing.T) {
},
},
},
// One table lookup, lookup not walked, labels kept.
{
node: &Node{Oid: "1", Label: "root",
Children: []*Node{
{Oid: "1.1", Label: "octet",
Children: []*Node{
{Oid: "1.1.1", Label: "octetEntry", Indexes: []string{"octetIndex"},
Children: []*Node{
{Oid: "1.1.1.1", Access: "ACCESS_READONLY", Label: "octetIndex", Type: "INTEGER"},
{Oid: "1.1.1.2", Access: "ACCESS_READONLY", Label: "octetDesc", Type: "OCTETSTR"},
{Oid: "1.1.1.3", Access: "ACCESS_READONLY", Label: "octetFoo", Type: "INTEGER"}}}}}}},
cfg: &ModuleConfig{
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octetIndex"},
NewIndex: "octetDesc",
KeepOld: true,
},
},
},
out: &config.Module{
// Walk is expanded to include the lookup OID.
Walk: []string{"1.1.1.2", "1.1.1.3"},
Metrics: []*config.Metric{
{
Name: "octetFoo",
Oid: "1.1.1.3",
Help: " - 1.1.1.3",
Type: "gauge",
Indexes: []*config.Index{
{
Labelname: "octetIndex",
Type: "gauge",
},
},
Lookups: []*config.Lookup{
{
Labels: []string{"octetIndex"},
Labelname: "octetDesc",
Type: "OctetString",
Oid: "1.1.1.2",
},
},
},
},
},
},
// One table lookup, lookup not walked.
{
node: &Node{Oid: "1", Label: "root",
Expand Down

0 comments on commit f4998bc

Please sign in to comment.