diff --git a/check.go b/check.go index 9e0ecf8..87ee4d7 100644 --- a/check.go +++ b/check.go @@ -5,12 +5,12 @@ import ( "context" "errors" "fmt" + "log/slog" "os" "strings" "time" "github.com/masterzen/winrm" - log "github.com/sirupsen/logrus" "github.com/spf13/pflag" "golang.org/x/crypto/ssh" ) @@ -126,7 +126,7 @@ func (c *Config) Validate() (err error) { if c.AuthType == "" { c.AuthType = AuthTLS } else { - log.Warnf("auth type is %s, but TLS certificates are supplied", c.AuthType) + slog.Warn(fmt.Sprintf("auth type is %s, but TLS certificates are supplied", c.AuthType)) } } @@ -175,10 +175,11 @@ func (c *Config) BuildCommand() (cmd string) { cmd = fmt.Sprintf(wrap, c.Command) } - log.WithField("cmd", cmd).Debug("prepared pwsh for execution") + slog.Debug("prepared pwsh for execution", "cmd", cmd) cmd = winrm.Powershell(cmd) - log.WithField("cmd", cmd).Debug("prepared winrm command for execution") + + slog.Debug("prepared winrm command for execution", "cmd", cmd) return } @@ -188,8 +189,6 @@ func (c *Config) Run(timeout time.Duration) (rc int, output string, err error) { panic("you need to call Validate() before Run()") } - log.WithField("config", *c).Debug("Running check with config") - endpoint := winrm.NewEndpoint( c.Host, // Host to connect to c.Port, // Winrm port @@ -254,11 +253,5 @@ func (c *Config) Run(timeout time.Duration) (rc int, output string, err error) { output = stdout.String() - // Info the debug output can confuse testing - if log.GetLevel() >= log.DebugLevel && stderr.Len() > 0 { - output += fmt.Sprintln("stderr contained:") - output += fmt.Sprintln(stderr.String()) - } - return } diff --git a/go.mod b/go.mod index 600457a..2563f7a 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.25.0 require ( github.com/NETWAYS/go-check v0.6.4 github.com/masterzen/winrm v0.0.0-20260407182533-5570be7f80cf - github.com/sirupsen/logrus v1.9.4 github.com/spf13/pflag v1.0.10 github.com/stretchr/testify v1.11.1 golang.org/x/crypto v0.50.0 diff --git a/go.sum b/go.sum index 4511054..f93f3dc 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,6 @@ github.com/masterzen/winrm v0.0.0-20260407182533-5570be7f80cf h1:UxGs98qiSWMqoqQ github.com/masterzen/winrm v0.0.0-20260407182533-5570be7f80cf/go.mod h1:JajVhkiG2bYSNYYPYuWG7WZHr42CTjMTcCjfInRNCqc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= -github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/main.go b/main.go index 440859d..da5d8bc 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log/slog" "os" "time" @@ -53,6 +54,11 @@ func main() { config := BuildConfigFlags(plugin.FlagSet) plugin.ParseArguments() + if plugin.Debug { + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) + slog.SetDefault(logger) + } + err := config.Validate() if err != nil { check.ExitRaw(check.Unknown, "could not validate parameters: "+err.Error())