Skip to content

Commit 8e8f8c1

Browse files
committed
Add two option:
- add the possibility to indicate a custom label name for a specific oid - add the possibility to indicate a static number as index for a specific oid Signed-off-by: earendilfr <[email protected]>
1 parent 2fc7f4f commit 8e8f8c1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

collector/collector.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,11 @@ func indexesToLabels(indexOids []int, metric *config.Metric, oidToPdu map[string
971971
}
972972
oid := lookup.Oid
973973
for _, label := range lookup.Labels {
974-
oid = fmt.Sprintf("%s.%s", oid, listToOid(labelOids[label]))
974+
if _, err := strconv.ParseUint(label, 10, 64); err == nil {
975+
oid = fmt.Sprintf("%s.%v", oid, label)
976+
} else {
977+
oid = fmt.Sprintf("%s.%s", oid, listToOid(labelOids[label]))
978+
}
975979
}
976980
if pdu, ok := oidToPdu[oid]; ok {
977981
t := lookup.Type

generator/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,5 @@ type Lookup struct {
8585
SourceIndexes []string `yaml:"source_indexes"`
8686
Lookup string `yaml:"lookup"`
8787
DropSourceIndexes bool `yaml:"drop_source_indexes,omitempty"`
88+
CustomLabelName string `yaml:"custom_label_name,omitempty"`
8889
}

generator/tree.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
445445
}
446446
}
447447
}
448+
if foundIndexes != len(lookup.SourceIndexes) {
449+
for _, index := range lookup.SourceIndexes {
450+
if _, err := strconv.ParseUint(index, 10, 64); err == nil {
451+
foundIndexes++
452+
}
453+
}
454+
}
448455
if foundIndexes == len(lookup.SourceIndexes) {
449456
if _, ok := nameToNode[lookup.Lookup]; !ok {
450457
return nil, fmt.Errorf("unknown index '%s'", lookup.Lookup)
@@ -459,6 +466,9 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
459466
Type: typ,
460467
Oid: indexNode.Oid,
461468
}
469+
if len(lookup.CustomLabelName) > 0 {
470+
l.Labelname = sanitizeLabelName(lookup.CustomLabelName)
471+
}
462472
for _, oldIndex := range lookup.SourceIndexes {
463473
l.Labels = append(l.Labels, sanitizeLabelName(oldIndex))
464474
}

0 commit comments

Comments
 (0)