Example #1
0
func (c CommandRunner) Run(
	e *Exec,
	command string,
	acc telegraf.Accumulator,
) ([]byte, error) {
	split_cmd, err := shellquote.Split(command)
	if err != nil || len(split_cmd) == 0 {
		return nil, fmt.Errorf("exec: unable to parse command, %s", err)
	}

	cmd := exec.Command(split_cmd[0], split_cmd[1:]...)

	var out bytes.Buffer
	cmd.Stdout = &out

	if err := internal.RunTimeout(cmd, e.Timeout.Duration); err != nil {
		switch e.parser.(type) {
		case *nagios.NagiosParser:
			AddNagiosState(err, acc)
		default:
			return nil, fmt.Errorf("exec: %s for command '%s'", err, command)
		}
	} else {
		switch e.parser.(type) {
		case *nagios.NagiosParser:
			AddNagiosState(nil, acc)
		}
	}

	return out.Bytes(), nil
}
Example #2
0
// Shell out to varnish_stat and return the output
func varnishRunner(cmdName string) (*bytes.Buffer, error) {
	cmdArgs := []string{"-1"}

	cmd := exec.Command(cmdName, cmdArgs...)
	var out bytes.Buffer
	cmd.Stdout = &out
	err := internal.RunTimeout(cmd, time.Millisecond*200)
	if err != nil {
		return &out, fmt.Errorf("error running varnishstat: %s", err)
	}

	return &out, nil
}
Example #3
0
			return true
		}

		_, found := filter[stat]
		return found
	}
}

// Shell out to varnish_stat and return the output
var varnishStat = func(cmdName string) (*bytes.Buffer, error) {
	cmdArgs := []string{"-1"}

	cmd := exec.Command(cmdName, cmdArgs...)
	var out bytes.Buffer
	cmd.Stdout = &out
	err := internal.RunTimeout(cmd, time.Millisecond*200)
	if err != nil {
		return &out, fmt.Errorf("error running varnishstat: %s", err)
	}

	return &out, nil
}

// Gather collects the configured stats from varnish_stat and adds them to the
// Accumulator
//
// The prefix of each stat (eg MAIN, MEMPOOL, LCK, etc) will be used as a
// 'section' tag and all stats that share that prefix will be reported as fields
// with that tag
func (s *Varnish) Gather(acc telegraf.Accumulator) error {
	s.setDefaults()