Skip to content

Commit

Permalink
fix(inputs.snmp): Fix crash when trying to format fields from unknown…
Browse files Browse the repository at this point in the history
… OIDs (#16155)

(cherry picked from commit 58b4126)
  • Loading branch information
Hipska authored and srebhan committed Nov 18, 2024
1 parent e5a0ce9 commit 207c8b0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/snmp/translator_gosmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/influxdata/telegraf"
)

var errCannotFormatUnkownType = errors.New("cannot format value, unknown type")

type gosmiTranslator struct {
}

Expand Down Expand Up @@ -64,14 +66,18 @@ func (g *gosmiTranslator) SnmpFormatEnum(oid string, value interface{}, full boo
return "", err
}

if node.Type == nil {
return "", errCannotFormatUnkownType
}

var v models.Value
if full {
v = node.FormatValue(value, models.FormatEnumName, models.FormatEnumValue)
} else {
v = node.FormatValue(value, models.FormatEnumName)
}

return v.Formatted, nil
return v.String(), nil
}

func getIndex(mibPrefix string, node gosmi.SmiNode) (col []string, tagOids map[string]struct{}) {
Expand Down

0 comments on commit 207c8b0

Please sign in to comment.