Skip to content

Commit

Permalink
generator/tree.go: Add support for subsequent address family in combi… (
Browse files Browse the repository at this point in the history
#782)

* generator/tree.go: Add support for subsequent address family in combined type

Since some MIB carry information about Safi (subsequent address family),
it will cause the generator to bail out, even though there is a valid Subtype before.

E.g.
Afi
Safi
Address

This is especially valid for Juniper BGP MIB.

Link: https://learningnetwork.cisco.com/s/question/0D53i00000KssMOCAZ/bgp-afi-and-safi

Signed-off-by: Josef Johansson <[email protected]>

* Update generator/tree.go

Signed-off-by: Ben Kochie <[email protected]>

---------

Signed-off-by: Josef Johansson <[email protected]>
Signed-off-by: Ben Kochie <[email protected]>
Co-authored-by: Ben Kochie <[email protected]>
  • Loading branch information
isodude and SuperQ authored Nov 24, 2023
1 parent 1476235 commit e7c07c6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
return // Ignored metric.
}

// Afi (Address family)
prevType := ""
// Safi (Subsequent address family, e.g. Multicast/Unicast)
prev2Type := ""
for count, i := range n.Indexes {
index := &config.Index{Labelname: i}
indexNode, ok := nameToNode[i]
Expand All @@ -383,11 +386,14 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
if subtype, ok := combinedTypes[index.Type]; ok {
if prevType == subtype {
metric.Indexes = metric.Indexes[:len(metric.Indexes)-1]
} else if prev2Type == subtype {
metric.Indexes = metric.Indexes[:len(metric.Indexes)-2]
} else {
level.Warn(logger).Log("msg", "Can't handle index type on node, missing preceding", "node", n.Label, "type", index.Type, "missing", subtype)
return
}
}
prev2Type = prevType
prevType = indexNode.TextualConvention
metric.Indexes = append(metric.Indexes, index)
}
Expand Down

0 comments on commit e7c07c6

Please sign in to comment.