Add command logging to snmp input at debug level (#5474)

This commit is contained in:
Daniel Nelson 2019-02-25 11:04:34 -08:00 committed by GitHub
parent 2abed0e04f
commit 0882479cbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"log"
"math" "math"
"net" "net"
"os/exec" "os/exec"
@ -15,7 +16,7 @@ import (
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/wlog"
"github.com/soniah/gosnmp" "github.com/soniah/gosnmp"
) )
@ -84,6 +85,14 @@ var execCommand = exec.Command
// execCmd executes the specified command, returning the STDOUT content. // execCmd executes the specified command, returning the STDOUT content.
// If command exits with error status, the output is captured into the returned error. // If command exits with error status, the output is captured into the returned error.
func execCmd(arg0 string, args ...string) ([]byte, error) { func execCmd(arg0 string, args ...string) ([]byte, error) {
if wlog.LogLevel() == wlog.DEBUG {
quoted := make([]string, 0, len(args))
for _, arg := range args {
quoted = append(quoted, fmt.Sprintf("%q", arg))
}
log.Printf("D! [inputs.snmp] Executing %q %s", arg0, strings.Join(quoted, " "))
}
out, err := execCommand(arg0, args...).Output() out, err := execCommand(arg0, args...).Output()
if err != nil { if err != nil {
if err, ok := err.(*exec.ExitError); ok { if err, ok := err.(*exec.ExitError); ok {