telegraf/plugins/inputs/execd/execd_windows.go

34 lines
579 B
Go
Raw Normal View History

//go:build windows
2020-02-29 02:46:03 +08:00
package execd
import (
"fmt"
"io"
"os"
"time"
2020-02-29 02:46:03 +08:00
"github.com/influxdata/telegraf"
)
func (e *Execd) Gather(acc telegraf.Accumulator) error {
2020-06-05 07:09:22 +08:00
if e.process == nil {
2020-02-29 02:46:03 +08:00
return nil
}
switch e.Signal {
case "STDIN":
2020-06-05 07:09:22 +08:00
if osStdin, ok := e.process.Stdin.(*os.File); ok {
osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second))
}
2020-06-05 07:09:22 +08:00
if _, err := io.WriteString(e.process.Stdin, "\n"); err != nil {
return fmt.Errorf("Error writing to stdin: %s", err)
}
2020-02-29 02:46:03 +08:00
case "none":
default:
return fmt.Errorf("invalid signal: %s", e.Signal)
}
return nil
}