This commit is contained in:
Thibault Cohen 2016-04-17 22:08:56 -04:00
parent d638f6e411
commit 4dce6d1ef9
2 changed files with 9 additions and 6 deletions

View File

@ -398,15 +398,16 @@ func (s *Snmp) Gather(acc telegraf.Accumulator) error {
// only if len(s.OidInstanceMapping) == 0 // only if len(s.OidInstanceMapping) == 0
if len(OidInstanceMapping) >= 0 { if len(OidInstanceMapping) >= 0 {
if err := host.SNMPMap(acc, s.nameToOid, s.subTableMap); err != nil { if err := host.SNMPMap(acc, s.nameToOid, s.subTableMap); err != nil {
return err log.Printf("SNMP Mapping error for host '%s': %s", host.Address, err)
continue
} }
} }
// Launch Get requests // Launch Get requests
if err := host.SNMPGet(acc, s.initNode); err != nil { if err := host.SNMPGet(acc, s.initNode); err != nil {
return err log.Printf("SNMP Error for host '%s': %s", host.Address, err)
} }
if err := host.SNMPBulk(acc, s.initNode); err != nil { if err := host.SNMPBulk(acc, s.initNode); err != nil {
return err log.Printf("SNMP Error for host '%s': %s", host.Address, err)
} }
} }
return nil return nil

View File

@ -5,7 +5,7 @@ import (
"github.com/influxdata/telegraf/testutil" "github.com/influxdata/telegraf/testutil"
// "github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -45,7 +45,8 @@ func TestSNMPErrorGet2(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
err := s.Gather(&acc) err := s.Gather(&acc)
require.Error(t, err) require.NoError(t, err)
assert.Equal(t, 0, len(acc.Metrics))
} }
func TestSNMPErrorBulk(t *testing.T) { func TestSNMPErrorBulk(t *testing.T) {
@ -65,7 +66,8 @@ func TestSNMPErrorBulk(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
err := s.Gather(&acc) err := s.Gather(&acc)
require.Error(t, err) require.NoError(t, err)
assert.Equal(t, 0, len(acc.Metrics))
} }
func TestSNMPGet1(t *testing.T) { func TestSNMPGet1(t *testing.T) {