Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inputs.snmp): Fix crash when trying to format fields from unknown OIDs #16155

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions 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 (g *gosmiTranslator) SnmpFormatDisplayHint(oid string, value interface{}) (string, error) {
Expand All @@ -85,9 +91,11 @@ func (g *gosmiTranslator) SnmpFormatDisplayHint(oid string, value interface{}) (
return "", err
}

v := node.FormatValue(value)
if node.Type == nil {
return "", errCannotFormatUnkownType
}

return v.Formatted, nil
return node.FormatValue(value).String(), nil
}

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