From 0882479cbfb8fa7823f5f1b7b7733d65b190c83a Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Mon, 25 Feb 2019 11:04:34 -0800 Subject: [PATCH] Add command logging to snmp input at debug level (#5474) --- plugins/inputs/snmp/snmp.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index 112e85c7c..24250c22a 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "fmt" + "log" "math" "net" "os/exec" @@ -15,7 +16,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/inputs" - + "github.com/influxdata/wlog" "github.com/soniah/gosnmp" ) @@ -84,6 +85,14 @@ var execCommand = exec.Command // execCmd executes the specified command, returning the STDOUT content. // If command exits with error status, the output is captured into the returned 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() if err != nil { if err, ok := err.(*exec.ExitError); ok {