@@ -107,8 +107,7 @@ func prepareTree(nodes *Node, logger *slog.Logger) map[string]*Node {
107107 walkNode (nodes , func (n * Node ) {
108108 // Set type on MAC addresses and strings.
109109 // RFC 2579
110- switch n .Hint {
111- case "1x:" :
110+ if n .Hint == "1x:" {
112111 n .Type = "PhysAddress48"
113112 }
114113 if displayStringRe .MatchString (n .Hint ) {
@@ -395,11 +394,12 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
395394
396395 // Convert (InetAddressType,InetAddress) to (InetAddress)
397396 if subtype , ok := combinedTypes [index .Type ]; ok {
398- if prevType == subtype {
397+ switch subtype {
398+ case prevType :
399399 metric .Indexes = metric .Indexes [:len (metric .Indexes )- 1 ]
400- } else if prev2Type == subtype {
400+ case prev2Type :
401401 metric .Indexes = metric .Indexes [:len (metric .Indexes )- 2 ]
402- } else {
402+ default :
403403 logger .Warn ("Can't handle index type on node, missing preceding" , "node" , n .Label , "type" , index .Type , "missing" , subtype )
404404 return
405405 }
@@ -513,41 +513,43 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
513513 // Check that the object before an InetAddress is an InetAddressType.
514514 // If not, change it to an OctetString.
515515 for _ , metric := range out .Metrics {
516- if metric .Type == "InetAddress" || metric .Type == "InetAddressMissingSize" {
517- // Get previous oid.
518- oids := strings .Split (metric .Oid , "." )
519- i , _ := strconv .Atoi (oids [len (oids )- 1 ])
520- oids [len (oids )- 1 ] = strconv .Itoa (i - 1 )
521- prevOid := strings .Join (oids , "." )
522- if prevObj , ok := nameToNode [prevOid ]; ! ok || prevObj .TextualConvention != "InetAddressType" {
523- metric .Type = "OctetString"
524- } else {
525- // Make sure the InetAddressType is included.
526- if len (tableInstances [metric .Oid ]) > 0 {
527- for _ , index := range tableInstances [metric .Oid ] {
528- needToWalk [prevOid + index + "." ] = struct {}{}
529- }
530- } else {
531- needToWalk [prevOid ] = struct {}{}
516+ if metric .Type != "InetAddress" && metric .Type != "InetAddressMissingSize" {
517+ continue
518+ }
519+ // Get previous oid.
520+ oids := strings .Split (metric .Oid , "." )
521+ i , _ := strconv .Atoi (oids [len (oids )- 1 ])
522+ oids [len (oids )- 1 ] = strconv .Itoa (i - 1 )
523+ prevOid := strings .Join (oids , "." )
524+ if prevObj , ok := nameToNode [prevOid ]; ! ok || prevObj .TextualConvention != "InetAddressType" {
525+ metric .Type = "OctetString"
526+ } else {
527+ // Make sure the InetAddressType is included.
528+ if len (tableInstances [metric .Oid ]) > 0 {
529+ for _ , index := range tableInstances [metric .Oid ] {
530+ needToWalk [prevOid + index + "." ] = struct {}{}
532531 }
532+ } else {
533+ needToWalk [prevOid ] = struct {}{}
533534 }
534535 }
535536 }
536537
537538 // Apply module config overrides to their corresponding metrics.
538539 for name , params := range cfg .Overrides {
539540 for _ , metric := range out .Metrics {
540- if name == metric .Name || name == metric .Oid {
541- metric .RegexpExtracts = params .RegexpExtracts
542- metric .DateTimePattern = params .DateTimePattern
543- metric .Offset = params .Offset
544- metric .Scale = params .Scale
545- if params .Help != "" {
546- metric .Help = params .Help
547- }
548- if params .Name != "" {
549- metric .Name = params .Name
550- }
541+ if name != metric .Name && name != metric .Oid {
542+ continue
543+ }
544+ metric .RegexpExtracts = params .RegexpExtracts
545+ metric .DateTimePattern = params .DateTimePattern
546+ metric .Offset = params .Offset
547+ metric .Scale = params .Scale
548+ if params .Help != "" {
549+ metric .Help = params .Help
550+ }
551+ if params .Name != "" {
552+ metric .Name = params .Name
551553 }
552554 }
553555 }
0 commit comments