Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log/slog"
"os"
"time"

Expand Down Expand Up @@ -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())
Expand Down
Loading