Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

fix(snmp): inherit dim algorithm if not set #737

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion modules/snmp/charts.go
Expand Up @@ -77,7 +77,7 @@ func newChart(cfg ChartConfig) (*module.Chart, error) {
}

if chart.Title == "" {
chart.Title = "Untilted chart"
chart.Title = "Untitled chart"
}
if chart.Units == "" {
chart.Units = "num"
Expand All @@ -86,7 +86,13 @@ func newChart(cfg ChartConfig) (*module.Chart, error) {
chart.Priority += module.Priority
}

seen := make(map[string]struct{})
var a string
for _, cfg := range cfg.Dimensions {
if cfg.Algorithm != "" {
seen[cfg.Algorithm] = struct{}{}
a = cfg.Algorithm
}
dim := &module.Dim{
ID: strings.TrimPrefix(cfg.OID, "."),
Name: cfg.Name,
Expand All @@ -98,6 +104,13 @@ func newChart(cfg ChartConfig) (*module.Chart, error) {
return nil, err
}
}
if len(seen) == 1 && a != "" && len(chart.Dims) > 1 {
for _, d := range chart.Dims {
if d.Algo == "" {
d.Algo = module.DimAlgo(a)
}
}
}

return chart, nil
}