snmp: make snmptranslate not required (#2008)
This commit is contained in:
parent
efb64a049f
commit
91143dda1a
|
@ -21,6 +21,12 @@
|
||||||
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin.
|
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin.
|
||||||
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus
|
- [#1775](https://github.com/influxdata/telegraf/issues/1775): Cache & expire metrics for delivery to prometheus
|
||||||
|
|
||||||
|
## v1.1.2 [2016-12-12]
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
|
||||||
|
- [#2007](https://github.com/influxdata/telegraf/issues/2007): Make snmptranslate not required when using numeric OID.
|
||||||
|
|
||||||
## v1.1.1 [2016-11-14]
|
## v1.1.1 [2016-11-14]
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
|
@ -848,6 +848,11 @@ func snmpTranslate(oid string) (mibName string, oidNum string, oidText string, c
|
||||||
out, err = execCmd("snmptranslate", "-Td", "-Ob", oid)
|
out, err = execCmd("snmptranslate", "-Td", "-Ob", oid)
|
||||||
} else {
|
} else {
|
||||||
out, err = execCmd("snmptranslate", "-Td", "-Ob", "-m", "all", oid)
|
out, err = execCmd("snmptranslate", "-Td", "-Ob", "-m", "all", oid)
|
||||||
|
if err, ok := err.(*exec.Error); ok && err.Err == exec.ErrNotFound {
|
||||||
|
// Silently discard error if snmptranslate not found and we have a numeric OID.
|
||||||
|
// Meaning we can get by without the lookup.
|
||||||
|
return "", oid, oid, "", nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", "", err
|
return "", "", "", "", err
|
||||||
|
|
|
@ -4,6 +4,7 @@ package snmp
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -198,6 +199,56 @@ func TestSnmpInit(t *testing.T) {
|
||||||
}, s.Fields[0])
|
}, s.Fields[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSnmpInit_noTranslate(t *testing.T) {
|
||||||
|
// override execCommand so it returns exec.ErrNotFound
|
||||||
|
defer func(ec func(string, ...string) *exec.Cmd) { execCommand = ec }(execCommand)
|
||||||
|
execCommand = func(_ string, _ ...string) *exec.Cmd {
|
||||||
|
return exec.Command("snmptranslateExecErrNotFound")
|
||||||
|
}
|
||||||
|
|
||||||
|
s := &Snmp{
|
||||||
|
Fields: []Field{
|
||||||
|
{Oid: ".1.1.1.1", Name: "one", IsTag: true},
|
||||||
|
{Oid: ".1.1.1.2", Name: "two"},
|
||||||
|
{Oid: ".1.1.1.3"},
|
||||||
|
},
|
||||||
|
Tables: []Table{
|
||||||
|
{Fields: []Field{
|
||||||
|
{Oid: ".1.1.1.4", Name: "four", IsTag: true},
|
||||||
|
{Oid: ".1.1.1.5", Name: "five"},
|
||||||
|
{Oid: ".1.1.1.6"},
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.init()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.1", s.Fields[0].Oid)
|
||||||
|
assert.Equal(t, "one", s.Fields[0].Name)
|
||||||
|
assert.Equal(t, true, s.Fields[0].IsTag)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.2", s.Fields[1].Oid)
|
||||||
|
assert.Equal(t, "two", s.Fields[1].Name)
|
||||||
|
assert.Equal(t, false, s.Fields[1].IsTag)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.3", s.Fields[2].Oid)
|
||||||
|
assert.Equal(t, ".1.1.1.3", s.Fields[2].Name)
|
||||||
|
assert.Equal(t, false, s.Fields[2].IsTag)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.4", s.Tables[0].Fields[0].Oid)
|
||||||
|
assert.Equal(t, "four", s.Tables[0].Fields[0].Name)
|
||||||
|
assert.Equal(t, true, s.Tables[0].Fields[0].IsTag)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.5", s.Tables[0].Fields[1].Oid)
|
||||||
|
assert.Equal(t, "five", s.Tables[0].Fields[1].Name)
|
||||||
|
assert.Equal(t, false, s.Tables[0].Fields[1].IsTag)
|
||||||
|
|
||||||
|
assert.Equal(t, ".1.1.1.6", s.Tables[0].Fields[2].Oid)
|
||||||
|
assert.Equal(t, ".1.1.1.6", s.Tables[0].Fields[2].Name)
|
||||||
|
assert.Equal(t, false, s.Tables[0].Fields[2].IsTag)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetSNMPConnection_v2(t *testing.T) {
|
func TestGetSNMPConnection_v2(t *testing.T) {
|
||||||
s := &Snmp{
|
s := &Snmp{
|
||||||
Timeout: internal.Duration{Duration: 3 * time.Second},
|
Timeout: internal.Duration{Duration: 3 * time.Second},
|
||||||
|
|
Loading…
Reference in New Issue