From 824b653e492c9c6d7c42379e139ef031f40c427d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 10:40:13 +0000 Subject: [PATCH 1/6] build(deps): bump golang.org/x/oauth2 from 0.35.0 to 0.36.0 Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.35.0 to 0.36.0. - [Commits](https://github.com/golang/oauth2/compare/v0.35.0...v0.36.0) --- updated-dependencies: - dependency-name: golang.org/x/oauth2 dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 4ea0600..3f6abb1 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module github.com/NETWAYS/check_sophos_central -go 1.24.0 +go 1.25.0 require ( github.com/NETWAYS/go-check v0.6.4 github.com/jarcoal/httpmock v1.4.1 github.com/spf13/pflag v1.0.10 - golang.org/x/oauth2 v0.35.0 + golang.org/x/oauth2 v0.36.0 ) diff --git a/go.sum b/go.sum index 9e4e437..9d68e43 100644 --- a/go.sum +++ b/go.sum @@ -8,5 +8,5 @@ github.com/maxatome/go-testdeep v1.14.0 h1:rRlLv1+kI8eOI3OaBXZwb3O7xY3exRzdW5QyX github.com/maxatome/go-testdeep v1.14.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= -golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= +golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= +golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= From a65d46ca0839ee17f4c0d5242bf94094086fc0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 9 Mar 2026 14:43:05 +0100 Subject: [PATCH 2/6] Use golang 1.26 in ci --- .github/workflows/build.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9b5a67..7a8d93d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v6 with: - go-version: 1.24 + go-version: 1.26 - name: Vet run: go vet ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6ec6004..7eb1958 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,4 +17,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v9 with: - version: v2.1.6 + version: v2.11.2 From 6d244912c814ed12ad589bc0d5accfe842f067f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 9 Mar 2026 14:58:48 +0100 Subject: [PATCH 3/6] Remove now useless perfdatalist implementation --- alerts.go | 15 +++++++++------ endpoints.go | 17 ++++++++++------- perfdata.go | 34 ---------------------------------- 3 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 perfdata.go diff --git a/alerts.go b/alerts.go index f01c53d..9fe6fe2 100644 --- a/alerts.go +++ b/alerts.go @@ -7,6 +7,7 @@ import ( "github.com/NETWAYS/check_sophos_central/api" "github.com/NETWAYS/go-check" + "github.com/NETWAYS/go-check/perfdata" ) type AlertOverview struct { @@ -104,10 +105,12 @@ func (o *AlertOverview) GetOutput() (s string) { } func (o *AlertOverview) GetPerfdata() string { - return PerfdataList{ - {Name: "alerts", Value: strconv.Itoa(o.Total)}, - {Name: "alerts_high", Value: strconv.Itoa(o.High)}, - {Name: "alerts_medium", Value: strconv.Itoa(o.Medium)}, - {Name: "alerts_low", Value: strconv.Itoa(o.Low)}, - }.String() + tmp := perfdata.PerfdataList{ + {Label: "alerts", Value: strconv.Itoa(o.Total)}, + {Label: "alerts_high", Value: strconv.Itoa(o.High)}, + {Label: "alerts_medium", Value: strconv.Itoa(o.Medium)}, + {Label: "alerts_low", Value: strconv.Itoa(o.Low)}, + } + + return tmp.String() } diff --git a/endpoints.go b/endpoints.go index 53e4fb7..df85156 100644 --- a/endpoints.go +++ b/endpoints.go @@ -6,6 +6,7 @@ import ( "github.com/NETWAYS/check_sophos_central/api" "github.com/NETWAYS/go-check" + "github.com/NETWAYS/go-check/perfdata" ) type EndpointOverview struct { @@ -104,11 +105,13 @@ func (o *EndpointOverview) GetOutput(limit int) (s string) { } func (o *EndpointOverview) GetPerfdata() string { - return PerfdataList{ - {Name: "endpoints_total", Value: strconv.Itoa(o.Total)}, - {Name: "endpoints_good", Value: strconv.Itoa(len(o.Good))}, - {Name: "endpoints_bad", Value: strconv.Itoa(len(o.Bad))}, - {Name: "endpoints_suspicious", Value: strconv.Itoa(len(o.Suspicious))}, - {Name: "endpoints_unknown", Value: strconv.Itoa(len(o.Unknown))}, - }.String() + tmp := perfdata.PerfdataList{ + {Label: "endpoints_total", Value: strconv.Itoa(o.Total)}, + {Label: "endpoints_good", Value: strconv.Itoa(len(o.Good))}, + {Label: "endpoints_bad", Value: strconv.Itoa(len(o.Bad))}, + {Label: "endpoints_suspicious", Value: strconv.Itoa(len(o.Suspicious))}, + {Label: "endpoints_unknown", Value: strconv.Itoa(len(o.Unknown))}, + } + + return tmp.String() } diff --git a/perfdata.go b/perfdata.go deleted file mode 100644 index 3a263e4..0000000 --- a/perfdata.go +++ /dev/null @@ -1,34 +0,0 @@ -package main - -import ( - "fmt" - "strings" -) - -type Perfdata struct { - Name string - Value string - Warn string - Crit string - Min string - Max string -} - -type PerfdataList []Perfdata - -func (p Perfdata) String() (s string) { - s = fmt.Sprintf("'%s'=%s;%s;%s;%s;%s", p.Name, p.Value, p.Warn, p.Crit, p.Min, p.Max) - s = strings.TrimRight(s, ";") - - return -} - -func (pl PerfdataList) String() (s string) { - for _, p := range pl { - s += p.String() + " " - } - - s = strings.Trim(s, " ") - - return -} From ff1d20881a18e72c89f828afb9486861aa740fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 9 Mar 2026 14:59:19 +0100 Subject: [PATCH 4/6] Fix linter complaints --- alerts.go | 3 +-- api/client.go | 1 - api/response.go | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/alerts.go b/alerts.go index 9fe6fe2..4ce020c 100644 --- a/alerts.go +++ b/alerts.go @@ -18,7 +18,7 @@ type AlertOverview struct { Output []string } -// Retrieve and process Alerts. +// CheckAlerts retrieves and processes alerts. // alertsToExclude is a list of strings that can the used to exclude alerts. func CheckAlerts(client *api.Client, names EndpointNames, alertsToExclude []string) (o *AlertOverview, err error) { o = &AlertOverview{} @@ -81,7 +81,6 @@ func (o *AlertOverview) GetSummary() string { return "alerts: " + strings.Join(states, ", ") } -// nolint: gocritic func (o *AlertOverview) GetStatus() int { if o.High > 0 { return check.Critical diff --git a/api/client.go b/api/client.go index 3202cbe..4a8155d 100644 --- a/api/client.go +++ b/api/client.go @@ -76,7 +76,6 @@ func (c *Client) NewDataRequest(method, url string, body io.Reader) (req *http.R } req, err = http.NewRequestWithContext(context.Background(), method, c.DataURL+"/"+url, body) - if err != nil { err = fmt.Errorf("could not create http request: %w", err) return diff --git a/api/response.go b/api/response.go index b3e159d..3027680 100644 --- a/api/response.go +++ b/api/response.go @@ -29,6 +29,7 @@ type PageInfo struct { Total int `json:"total"` } +// GetResults fetches data from the API via HTTP // nolint: funlen func (c *Client) GetResults(request *http.Request) (items []json.RawMessage, err error) { var ( From 3d18c88460b26f7e5a5308279cc0d863979d740f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 9 Mar 2026 15:02:15 +0100 Subject: [PATCH 5/6] Ignore not applicable linter issue --- api/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/client.go b/api/client.go index 4a8155d..1d961ee 100644 --- a/api/client.go +++ b/api/client.go @@ -87,7 +87,7 @@ func (c *Client) NewDataRequest(method, url string, body io.Reader) (req *http.R } func (c *Client) Do(req *http.Request) (res *http.Response, err error) { - res, err = c.HTTPClient.Do(req) + res, err = c.HTTPClient.Do(req) //nolint:gosec if err != nil { err = fmt.Errorf("HTTP request failed: %w", err) } From c02f9e8d305a98ddd5dcfd05bc15630b9c2b7729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Mon, 9 Mar 2026 15:10:37 +0100 Subject: [PATCH 6/6] Adapt perfdata types and string formatting in tests --- alerts.go | 9 ++++----- endpoints.go | 11 +++++------ main_test.go | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/alerts.go b/alerts.go index 4ce020c..388a0cd 100644 --- a/alerts.go +++ b/alerts.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strconv" "strings" "github.com/NETWAYS/check_sophos_central/api" @@ -105,10 +104,10 @@ func (o *AlertOverview) GetOutput() (s string) { func (o *AlertOverview) GetPerfdata() string { tmp := perfdata.PerfdataList{ - {Label: "alerts", Value: strconv.Itoa(o.Total)}, - {Label: "alerts_high", Value: strconv.Itoa(o.High)}, - {Label: "alerts_medium", Value: strconv.Itoa(o.Medium)}, - {Label: "alerts_low", Value: strconv.Itoa(o.Low)}, + {Label: "alerts", Value: o.Total}, + {Label: "alerts_high", Value: o.High}, + {Label: "alerts_medium", Value: o.Medium}, + {Label: "alerts_low", Value: o.Low}, } return tmp.String() diff --git a/endpoints.go b/endpoints.go index df85156..32a304f 100644 --- a/endpoints.go +++ b/endpoints.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strconv" "github.com/NETWAYS/check_sophos_central/api" "github.com/NETWAYS/go-check" @@ -106,11 +105,11 @@ func (o *EndpointOverview) GetOutput(limit int) (s string) { func (o *EndpointOverview) GetPerfdata() string { tmp := perfdata.PerfdataList{ - {Label: "endpoints_total", Value: strconv.Itoa(o.Total)}, - {Label: "endpoints_good", Value: strconv.Itoa(len(o.Good))}, - {Label: "endpoints_bad", Value: strconv.Itoa(len(o.Bad))}, - {Label: "endpoints_suspicious", Value: strconv.Itoa(len(o.Suspicious))}, - {Label: "endpoints_unknown", Value: strconv.Itoa(len(o.Unknown))}, + {Label: "endpoints_total", Value: o.Total}, + {Label: "endpoints_good", Value: len(o.Good)}, + {Label: "endpoints_bad", Value: len(o.Bad)}, + {Label: "endpoints_suspicious", Value: len(o.Suspicious)}, + {Label: "endpoints_unknown", Value: len(o.Unknown)}, } return tmp.String() diff --git a/main_test.go b/main_test.go index 6b64dd9..05908fe 100644 --- a/main_test.go +++ b/main_test.go @@ -39,7 +39,7 @@ func TestMainAlerts_GetPerfdata(t *testing.T) { }{ "simple-overview": { ao: AlertOverview{}, - expected: "'alerts'=0 'alerts_high'=0 'alerts_medium'=0 'alerts_low'=0", + expected: "alerts=0 alerts_high=0 alerts_medium=0 alerts_low=0", }, }