diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ed3666..cbc45b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: Go on: push: - branches: [ master ] + branches: [ main ] tags: - v* pull_request: @@ -19,7 +19,8 @@ jobs: - name: Set up Go uses: actions/setup-go@v6 with: - go-version: 1.26 + go-version: stable + check-latest: true - name: Vet run: go vet ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e423a01..a3103bb 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -4,7 +4,7 @@ on: tags: - v* branches: - - master + - main pull_request: jobs: @@ -17,4 +17,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.11.2 + version: v2.12.2 diff --git a/.golangci.yml b/.golangci.yml index f8246ab..7ffbe82 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,7 +3,12 @@ run: tests: false linters: default: all + enable: + - wsl_v5 + - gomodguard_v2 disable: + - wsl + - gomodguard - cyclop - depguard - err113 diff --git a/alerts.go b/alerts.go index 388a0cd..afc5661 100644 --- a/alerts.go +++ b/alerts.go @@ -6,7 +6,6 @@ import ( "github.com/NETWAYS/check_sophos_central/api" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" ) type AlertOverview struct { @@ -80,7 +79,7 @@ func (o *AlertOverview) GetSummary() string { return "alerts: " + strings.Join(states, ", ") } -func (o *AlertOverview) GetStatus() int { +func (o *AlertOverview) GetStatus() check.Status { if o.High > 0 { return check.Critical } else if o.Medium > 0 || o.Low > 0 { @@ -103,7 +102,7 @@ func (o *AlertOverview) GetOutput() (s string) { } func (o *AlertOverview) GetPerfdata() string { - tmp := perfdata.PerfdataList{ + tmp := check.PerfdataList{ {Label: "alerts", Value: o.Total}, {Label: "alerts_high", Value: o.High}, {Label: "alerts_medium", Value: o.Medium}, diff --git a/check.go b/check.go index 88f974c..0a830af 100644 --- a/check.go +++ b/check.go @@ -66,7 +66,7 @@ func (c *Config) Validate() error { return nil } -func (c *Config) Run() (rc int, output string, err error) { +func (c *Config) Run() (rc check.Status, output string, err error) { // Setup API client. client := api.NewClient(c.ClientID, c.ClientSecret) client.PageSize = c.PageSize diff --git a/endpoints.go b/endpoints.go index 32a304f..1351ee8 100644 --- a/endpoints.go +++ b/endpoints.go @@ -5,7 +5,6 @@ import ( "github.com/NETWAYS/check_sophos_central/api" "github.com/NETWAYS/go-check" - "github.com/NETWAYS/go-check/perfdata" ) type EndpointOverview struct { @@ -70,7 +69,7 @@ func (o *EndpointOverview) GetSummary() (s string) { return } -func (o *EndpointOverview) GetStatus() int { +func (o *EndpointOverview) GetStatus() check.Status { // nolint: gocritic if len(o.Bad) > 0 { return check.Critical @@ -104,7 +103,7 @@ func (o *EndpointOverview) GetOutput(limit int) (s string) { } func (o *EndpointOverview) GetPerfdata() string { - tmp := perfdata.PerfdataList{ + tmp := check.PerfdataList{ {Label: "endpoints_total", Value: o.Total}, {Label: "endpoints_good", Value: len(o.Good)}, {Label: "endpoints_bad", Value: len(o.Bad)}, diff --git a/go.mod b/go.mod index 3f6abb1..b303fb0 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,9 @@ module github.com/NETWAYS/check_sophos_central -go 1.25.0 +go 1.26 require ( - github.com/NETWAYS/go-check v0.6.4 + github.com/NETWAYS/go-check v1.0.0 github.com/jarcoal/httpmock v1.4.1 github.com/spf13/pflag v1.0.10 golang.org/x/oauth2 v0.36.0 diff --git a/go.sum b/go.sum index 9d68e43..f55e3e3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/NETWAYS/go-check v0.6.4 h1:4WETSVNZNEP0Yudcp5xlvxq6RGn920cmUKq4fz/P1GQ= -github.com/NETWAYS/go-check v0.6.4/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= +github.com/NETWAYS/go-check v1.0.0 h1:YkzTwFfGR+Z+mK3Wsqpnu8wibzsB30im19iPNfCOsMQ= +github.com/NETWAYS/go-check v1.0.0/go.mod h1:8/GWnq8SirreAixgRmcp82JG16NnEl38rHq9phICy9s= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/jarcoal/httpmock v1.4.1 h1:0Ju+VCFuARfFlhVXFc2HxlcQkfB+Xq12/EotHko+x2A= diff --git a/main.go b/main.go index 0b5cf5e..6633c2c 100644 --- a/main.go +++ b/main.go @@ -33,5 +33,5 @@ func main() { check.ExitError(err) } - check.ExitRaw(rc, output) + check.Exit(rc, output) } diff --git a/main_test.go b/main_test.go index 05908fe..870ae3c 100644 --- a/main_test.go +++ b/main_test.go @@ -2,6 +2,8 @@ package main import ( "testing" + + "github.com/NETWAYS/go-check" ) func TestMainCheck_matches(t *testing.T) { @@ -80,23 +82,23 @@ func TestMainAlerts_GetOutput(t *testing.T) { func TestMainAlerts_GetStatus(t *testing.T) { testcases := map[string]struct { ao AlertOverview - expected int + expected check.Status }{ "simple-overview": { ao: AlertOverview{}, - expected: 0, + expected: check.OK, }, "simple-warning": { ao: AlertOverview{ Medium: 1, }, - expected: 1, + expected: check.Warning, }, "simple-critical": { ao: AlertOverview{ High: 1, }, - expected: 2, + expected: check.Critical, }, }