Skip to content

Commit

Permalink
Invert logic of dropping source labels.
Browse files Browse the repository at this point in the history
Merge the if_mib example modules into one.

Use only the mibs we download.

Signed-off-by: Brian Brazil <[email protected]>
  • Loading branch information
brian-brazil committed Feb 5, 2019
1 parent bafb43b commit 94e3002
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 1,980 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
working_dir: ~/project/generator

environment:
MIBDIRS: mibs:/usr/share/snmp/mibs
MIBDIRS: mibs
steps:
- checkout:
path: ~/project
Expand Down
4 changes: 2 additions & 2 deletions generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ modules:
# with that value.
- source_indexes: [bsnDot11EssIndex]
lookup: bsnDot11EssSsid
keep_source_indexes: false # If true, don't delete source index labels for this lookup.
# This is useful when the new index has duplicates.
drop_source_indexes: false # If true, delete source index labels for this lookup.
# This avoids label clutter when the new index is unique.

overrides: # Allows for per-module overrides of bits of MIBs
metricName:
Expand Down
2 changes: 1 addition & 1 deletion generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ type ModuleConfig struct {
type Lookup struct {
SourceIndexes []string `yaml:"source_indexes"`
Lookup string `yaml:"lookup"`
KeepSourceIndexes bool `yaml:"keep_source_indexes,omitempty"`
DropSourceIndexes bool `yaml:"drop_source_indexes,omitempty"`
}
25 changes: 14 additions & 11 deletions generator/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ modules:
# Default IF-MIB interfaces table with ifIndex.
if_mib:
walk: [sysUpTime, interfaces, ifXTable]
# Interfaces if ifAlias is unique.
if_mib_ifalias:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
# Interfaces if ifDescr is unique.
if_mib_ifdescr:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- source_indexes: [ifIndex]
lookup: ifDescr
# Interfaces if ifName is unique.
if_mib_ifname:
walk: [sysUpTime, interfaces, ifXTable]
lookups:
- source_indexes: [ifIndex]
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
Expand All @@ -37,8 +26,10 @@ modules:
lookups:
- source_indexes: [bsnDot11EssIndex]
lookup: bsnDot11EssSsid
drop_source_indexes: true
- source_indexes: [bsnAPDot3MacAddress]
lookup: bsnAPName
drop_source_indexes: true

# APC/Schneider UPS Network Management Cards
#
Expand Down Expand Up @@ -70,8 +61,10 @@ modules:
lookups:
- source_indexes: [upsOutletGroupStatusIndex]
lookup: upsOutletGroupStatusName
drop_source_indexes: true
- source_indexes: [iemStatusProbeIndex]
lookup: iemStatusProbeName
drop_source_indexes: true

# ServerTech Sentry 3 MIB
#
Expand Down Expand Up @@ -161,21 +154,29 @@ modules:
lookups:
- source_indexes: [spaceIOIndex]
lookup: spaceIODevice
drop_source_indexes: true
- source_indexes: [storageIOIndex]
lookup: storageIODevice
drop_source_indexes: true
- source_indexes: [serviceInfoIndex]
lookup: serviceName
drop_source_indexes: true
- source_indexes: [ifIndex]
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
drop_source_indexes: true
- source_indexes: [diskIndex]
lookup: diskID
drop_source_indexes: true
- source_indexes: [raidIndex]
lookup: raidName
drop_source_indexes: true
- source_indexes: [laIndex]
lookup: laNames
drop_source_indexes: true
- source_indexes: [hrStorageIndex]
lookup: hrStorageDescr
drop_source_indexes: true

# DD-WRT
#
Expand All @@ -197,8 +198,10 @@ modules:
lookups:
- source_indexes: [ifIndex]
lookup: ifDescr
drop_source_indexes: true
- source_indexes: [laIndex]
lookup: laNames
drop_source_indexes: true

# Ubiquiti / AirMAX
#
Expand Down
2 changes: 1 addition & 1 deletion generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
} else {
needToWalk[indexNode.Oid] = struct{}{}
}
if !lookup.KeepSourceIndexes {
if lookup.DropSourceIndexes {
// Avoid leaving the old labelname around.
toDelete = append(toDelete, lookup.SourceIndexes...)
}
Expand Down
35 changes: 20 additions & 15 deletions generator/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,8 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
KeepSourceIndexes: true,
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
},
},
},
Expand Down Expand Up @@ -1003,8 +1002,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
SourceIndexes: []string{"octetIndex"},
Lookup: "octetDesc",
DropSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1053,8 +1053,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"octetIndex"},
Lookup: "1.1.1.2",
SourceIndexes: []string{"octetIndex"},
Lookup: "1.1.1.2",
DropSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1104,8 +1105,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octetFoo"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"octetIndex", "octetIndex2"},
Lookup: "octetDesc",
SourceIndexes: []string{"octetIndex", "octetIndex2"},
Lookup: "octetDesc",
DropSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1184,8 +1186,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"octet^Foo"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"octet&Index"},
Lookup: "1.1.1.2",
SourceIndexes: []string{"octet&Index"},
Lookup: "1.1.1.2",
DropSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1346,8 +1349,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"1.1.1.2.100", "1.1.1.4.100", "1.1.1.2.200"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
DropSourceIndexes: true,
},
},
},
Expand Down Expand Up @@ -1419,8 +1423,9 @@ func TestGenerateConfigModule(t *testing.T) {
Walk: []string{"1.1.1.2.100", "1.1.1.3"},
Lookups: []*Lookup{
{
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
SourceIndexes: []string{"tableIndex"},
Lookup: "tableDesc",
DropSourceIndexes: true,
},
},
},
Expand Down
Loading

0 comments on commit 94e3002

Please sign in to comment.