snmp: return error on unknown conversion type (#1853)

This commit is contained in:
Patrick Hemmer 2016-10-06 09:23:51 -04:00 committed by Cameron Sparr
parent 817d696628
commit 5a86a2ff26
1 changed files with 2 additions and 2 deletions

View File

@ -716,7 +716,6 @@ func (s *Snmp) getConnection(agent string) (snmpConnection, error) {
// "hwaddr" will convert the value into a MAC address. // "hwaddr" will convert the value into a MAC address.
// "ipaddr" will convert the value into into an IP address. // "ipaddr" will convert the value into into an IP address.
// "" will convert a byte slice into a string. // "" will convert a byte slice into a string.
// Any other conv will return the input value unchanged.
func fieldConvert(conv string, v interface{}) (interface{}, error) { func fieldConvert(conv string, v interface{}) (interface{}, error) {
if conv == "" { if conv == "" {
if bs, ok := v.([]byte); ok { if bs, ok := v.([]byte); ok {
@ -805,6 +804,7 @@ func fieldConvert(conv string, v interface{}) (interface{}, error) {
default: default:
return nil, fmt.Errorf("invalid type (%T) for hwaddr conversion", v) return nil, fmt.Errorf("invalid type (%T) for hwaddr conversion", v)
} }
return v, nil
} }
if conv == "ipaddr" { if conv == "ipaddr" {
@ -829,7 +829,7 @@ func fieldConvert(conv string, v interface{}) (interface{}, error) {
return v, nil return v, nil
} }
return v, nil return nil, fmt.Errorf("invalid conversion type '%s'", conv)
} }
// snmpTranslate resolves the given OID. // snmpTranslate resolves the given OID.