Skip to content

Instantly share code, notes, and snippets.

@SuperQ
Last active December 13, 2017 14:04
Show Gist options
  • Save SuperQ/b5f374a8d2ad44d51ebade54ce4767c2 to your computer and use it in GitHub Desktop.
Save SuperQ/b5f374a8d2ad44d51ebade54ce4767c2 to your computer and use it in GitHub Desktop.
snmp_exporter label adder
diff --git a/generator/generator.yml b/generator/generator.yml
index faef3fc..4783862 100644
--- a/generator/generator.yml
+++ b/generator/generator.yml
@@ -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:
- old_index: ifIndex
new_index: ifAlias
- # Interfaces if ifDescr is unique.
- if_mib_ifdescr:
- walk: [sysUpTime, interfaces, ifXTable]
- lookups:
- old_index: ifIndex
new_index: ifDescr
- # Interfaces if ifName is unique.
- if_mib_ifname:
- walk: [sysUpTime, interfaces, ifXTable]
- lookups:
- old_index: 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
diff --git a/generator/tree.go b/generator/tree.go
index d0d6b63..8fdc896 100644
--- a/generator/tree.go
+++ b/generator/tree.go
@@ -196,14 +196,12 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
log.Fatalf("Unknown index '%s'", lookup.NewIndex)
}
indexNode := nameToNode[lookup.NewIndex]
- // Avoid leaving the old labelname around.
- index.Labelname = sanitizeLabelName(indexNode.Label)
typ, ok := metricType(indexNode.Type)
if !ok {
log.Fatalf("Unknown index type %s for %s", indexNode.Type, lookup.NewIndex)
}
metric.Lookups = append(metric.Lookups, &config.Lookup{
- Labels: []string{sanitizeLabelName(indexNode.Label)},
+ Labels: []string{sanitizeLabelName(index.Labelname)},
Labelname: sanitizeLabelName(indexNode.Label),
Type: typ,
Oid: indexNode.Oid,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment