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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.1.6
version: v2.11.2
19 changes: 10 additions & 9 deletions alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"strconv"
"strings"

"github.com/NETWAYS/check_sophos_central/api"
"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
)

type AlertOverview struct {
Expand All @@ -17,7 +17,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{}
Expand Down Expand Up @@ -80,7 +80,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
Expand All @@ -104,10 +103,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: o.Total},
{Label: "alerts_high", Value: o.High},
{Label: "alerts_medium", Value: o.Medium},
{Label: "alerts_low", Value: o.Low},
}

return tmp.String()
}
3 changes: 1 addition & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,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)
}
Expand Down
1 change: 1 addition & 0 deletions api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 10 additions & 8 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"fmt"
"strconv"

"github.com/NETWAYS/check_sophos_central/api"
"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
)

type EndpointOverview struct {
Expand Down Expand Up @@ -104,11 +104,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: 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()
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down
34 changes: 0 additions & 34 deletions perfdata.go

This file was deleted.