telegraf/plugins/inputs/execd/execd_windows.go

39 lines
730 B
Go
Raw Permalink Normal View History

//go:build windows
2020-02-29 02:46:03 +08:00
package execd
import (
"errors"
2020-02-29 02:46:03 +08:00
"fmt"
"io"
"os"
"time"
2020-02-29 02:46:03 +08:00
"github.com/influxdata/telegraf"
)
func (e *Execd) Gather(_ 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 {
if err := osStdin.SetWriteDeadline(time.Now().Add(1 * time.Second)); err != nil {
if !errors.Is(err, os.ErrNoDeadline) {
return fmt.Errorf("setting write deadline failed: %w", err)
}
}
}
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: %w", err)
}
2020-02-29 02:46:03 +08:00
case "none":
default:
return fmt.Errorf("invalid signal: %s", e.Signal)
}
return nil
}