Skip to content

Commit

Permalink
feat: allow module name in generator.yml (#1333)
Browse files Browse the repository at this point in the history
Currently, some labels such as ifName and ifDescr are defined in
multiple modules and must be specified using OID.  This patch avails
such OIDs under both its bare label and module-qualified labels,
e.g. both "ifName" and "IF-MIB::ifName".

Signed-off-by: Eugene Kim <[email protected]>
Signed-off-by: Eugene Kim <[email protected]>
  • Loading branch information
astralblue authored Jan 8, 2025
1 parent d9a284e commit f5d509d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions generator/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ modules:
- source_indexes: [ifIndex]
lookup: ifAlias
- source_indexes: [ifIndex]
# Uis OID to avoid conflict with PaloAlto PAN-COMMON-MIB.
lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr
# Disambiguate from PaloAlto PAN-COMMON-MIB::ifDescr.
lookup: "IF-MIB::ifDescr"
- 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
# Disambiguate from Netscaler NS-ROOT-MIB::ifName.
lookup: "IF-MIB::ifName"
overrides:
ifAlias:
ignore: true # Lookup metric
Expand Down Expand Up @@ -856,7 +856,7 @@ modules:
- source_indexes: [ifIndex]
lookup: ifAlias
- source_indexes: [ifIndex]
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
lookup: "IF-MIB::ifName"
overrides:
ddmStatusBiasCurrent:
type: DisplayString
Expand Down
3 changes: 3 additions & 0 deletions generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func generateConfig(nodes *Node, nameToNode map[string]*Node, logger *slog.Logge
walkNode(mNodes, func(n *Node) {
mNameToNode[n.Oid] = n
mNameToNode[n.Label] = n
if n.Module != "" {
mNameToNode[n.Module+"::"+n.Label] = n
}
})
out, err := generateConfigModule(m, mNodes, mNameToNode, logger)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions generator/net_snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import (
type Node struct {
Oid string
subid int64
Module string
Label string
Augments string
Children []*Node
Expand Down Expand Up @@ -223,6 +224,9 @@ func buildMIBTree(t *C.struct_tree, n *Node, oid string) {
} else {
n.Oid = fmt.Sprintf("%d", t.subid)
}
if m := C.find_module(t.modid); m != nil {
n.Module = C.GoString(m.name)
}
n.Label = C.GoString(t.label)
if typ, ok := netSnmptypeMap[int(t._type)]; ok {
n.Type = typ
Expand Down

0 comments on commit f5d509d

Please sign in to comment.