Skip to content

Commit

Permalink
Make lookup config field names more understandable.
Browse files Browse the repository at this point in the history
old_indexes -> source_indexes
new_index -> lookup
keep_old -> keep_source_indexes

Signed-off-by: Brian Brazil <[email protected]>
  • Loading branch information
brian-brazil committed Sep 26, 2018
1 parent f4998bc commit ed67082
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ modules:
# 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.
- source_indexes: [bsnDot11EssIndex]
lookup: bsnDot11EssSsid
keep_sources_indexes: false # If true, don't delete source index labels for this lookup.

overrides: # Allows for per-module overrides of bits of MIBs
metricName:
Expand Down
6 changes: 3 additions & 3 deletions generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type ModuleConfig struct {
}

type Lookup struct {
OldIndexes []string `yaml:"old_indexes"`
NewIndex string `yaml:"new_index"`
KeepOld bool `yaml:"keep_old,omitempty"`
SourceIndexes []string `yaml:"source_indexes"`
Lookup string `yaml:"lookup"`
KeepSourceIndexes bool `yaml:"keep_source_indexes,omitempty"`
}
68 changes: 34 additions & 34 deletions generator/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ modules:
if_mib_ifalias:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_indexes: [ifIndex]
new_index: ifAlias
- source_indexes: [ifIndex]
lookup: ifAlias
# Interfaces if ifDescr is unique.
if_mib_ifdescr:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_indexes: [ifIndex]
new_index: ifDescr
- source_indexes: [ifIndex]
lookup: ifDescr
# Interfaces if ifName is unique.
if_mib_ifname:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- old_indexes: [ifIndex]
- source_indexes: [ifIndex]
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
new_index: 1.3.6.1.2.1.31.1.1.1.1 # ifName
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName

# Cicso Wireless LAN Controller
cisco_wlc:
Expand All @@ -35,10 +35,10 @@ modules:
- 1.3.6.1.4.1.14179.2.2.13.1.3 # bsnAPIfLoadChannelUtilization
- 1.3.6.1.4.1.14179.2.2.15.1.21 # bsnAPIfDBNoisePower
lookups:
- old_indexes: [bsnDot11EssIndex]
new_index: bsnDot11EssSsid
- old_indexes: [bsnAPDot3MacAddress]
new_index: bsnAPName
- source_indexes: [bsnDot11EssIndex]
lookup: bsnDot11EssSsid
- source_indexes: [bsnAPDot3MacAddress]
lookup: bsnAPName

# APC/Schneider UPS Network Management Cards
#
Expand Down Expand Up @@ -68,10 +68,10 @@ modules:
- 1.3.6.1.4.1.318.1.1.1.12 # upsOutletGroups
- 1.3.6.1.4.1.318.1.1.10.2.3.2 # iemStatusProbesTable
lookups:
- old_indexes: [upsOutletGroupStatusIndex]
new_index: upsOutletGroupStatusName
- old_indexes: [iemStatusProbeIndex]
new_index: iemStatusProbeName
- source_indexes: [upsOutletGroupStatusIndex]
lookup: upsOutletGroupStatusName
- source_indexes: [iemStatusProbeIndex]
lookup: iemStatusProbeName

# ServerTech Sentry 3 MIB
#
Expand Down Expand Up @@ -159,23 +159,23 @@ modules:
- 1.3.6.1.4.1.6574.102 # spaceIO
- 1.3.6.1.4.1.6574.104 # synologyiSCSILUN
lookups:
- old_indexes: [spaceIOIndex]
new_index: spaceIODevice
- old_indexes: [storageIOIndex]
new_index: storageIODevice
- old_indexes: [serviceInfoIndex]
new_index: serviceName
- old_indexes: [ifIndex]
- source_indexes: [spaceIOIndex]
lookup: spaceIODevice
- source_indexes: [storageIOIndex]
lookup: storageIODevice
- source_indexes: [serviceInfoIndex]
lookup: serviceName
- source_indexes: [ifIndex]
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
new_index: 1.3.6.1.2.1.31.1.1.1.1 # ifName
- old_indexes: [diskIndex]
new_index: diskID
- old_indexes: [raidIndex]
new_index: raidName
- old_indexes: [laIndex]
new_index: laNames
- old_indexes: [hrStorageIndex]
new_index: hrStorageDescr
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
- source_indexes: [diskIndex]
lookup: diskID
- source_indexes: [raidIndex]
lookup: raidName
- source_indexes: [laIndex]
lookup: laNames
- source_indexes: [hrStorageIndex]
lookup: hrStorageDescr

# DD-WRT
#
Expand All @@ -195,10 +195,10 @@ modules:
- 1.3.6.1.4.1.2021.10.1.5 # laLoadInt
- 1.3.6.1.4.1.2021.11 # systemStats
lookups:
- old_indexes: [ifIndex]
new_index: ifDescr
- old_indexes: [laIndex]
new_index: laNames
- source_indexes: [ifIndex]
lookup: ifDescr
- source_indexes: [laIndex]
lookup: laNames

# Ubiquiti / AirMAX
#
Expand Down
18 changes: 9 additions & 9 deletions generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,27 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
foundIndexes := 0
// See if all lookup indexes are present.
for _, index := range metric.Indexes {
for _, lookupIndex := range lookup.OldIndexes {
for _, lookupIndex := range lookup.SourceIndexes {
if index.Labelname == lookupIndex {
foundIndexes++
}
}
}
if foundIndexes == len(lookup.OldIndexes) {
if _, ok := nameToNode[lookup.NewIndex]; !ok {
log.Fatalf("Unknown index '%s'", lookup.NewIndex)
if foundIndexes == len(lookup.SourceIndexes) {
if _, ok := nameToNode[lookup.Lookup]; !ok {
log.Fatalf("Unknown index '%s'", lookup.Lookup)
}
indexNode := nameToNode[lookup.NewIndex]
indexNode := nameToNode[lookup.Lookup]
typ, ok := metricType(indexNode.Type)
if !ok {
log.Fatalf("Unknown index type %s for %s", indexNode.Type, lookup.NewIndex)
log.Fatalf("Unknown index type %s for %s", indexNode.Type, lookup.Lookup)
}
l := &config.Lookup{
Labelname: sanitizeLabelName(indexNode.Label),
Type: typ,
Oid: indexNode.Oid,
}
for _, oldIndex := range lookup.OldIndexes {
for _, oldIndex := range lookup.SourceIndexes {
l.Labels = append(l.Labels, sanitizeLabelName(oldIndex))
}
metric.Lookups = append(metric.Lookups, l)
Expand All @@ -407,9 +407,9 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
} else {
needToWalk[indexNode.Oid] = struct{}{}
}
if !lookup.KeepOld {
if !lookup.KeepSourceIndexes {
// Avoid leaving the old labelname around.
toDelete = append(toDelete, lookup.OldIndexes...)
toDelete = append(toDelete, lookup.SourceIndexes...)
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions generator/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octetIndex"},
NewIndex: "octetDesc",
KeepOld: true,
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
KeepSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1003,8 +1003,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octetIndex"},
NewIndex: "octetDesc",
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
},
},
},
Expand Down Expand Up @@ -1053,8 +1053,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octetIndex"},
NewIndex: "1.1.1.2",
SourceIndexes: []string{"octetIndex"},
Lookup: "1.1.1.2",
},
},
},
Expand Down Expand Up @@ -1104,8 +1104,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octetIndex", "octetIndex2"},
NewIndex: "octetDesc",
SourceIndexes: []string{"octetIndex", "octetIndex2"},
Lookup: "octetDesc",
},
},
},
Expand Down Expand Up @@ -1184,8 +1184,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octet^Foo"},
Lookups: []*Lookup{
{
OldIndexes: []string{"octet&Index"},
NewIndex: "1.1.1.2",
SourceIndexes: []string{"octet&Index"},
Lookup: "1.1.1.2",
},
},
},
Expand Down Expand Up @@ -1346,8 +1346,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"1.1.1.2.100", "1.1.1.4.100", "1.1.1.2.200"},
Lookups: []*Lookup{
{
OldIndexes: []string{"tableIndex"},
NewIndex: "tableDesc",
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
},
},
},
Expand Down Expand Up @@ -1419,8 +1419,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"1.1.1.2.100", "1.1.1.3"},
Lookups: []*Lookup{
{
OldIndexes: []string{"tableIndex"},
NewIndex: "tableDesc",
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
},
},
},
Expand Down

0 comments on commit ed67082

Please sign in to comment.