diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e173b5..9a7ea5e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: 1.21 - name: Test run: go test -v ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index d8d6fed..03ba16d 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,3 +16,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/cmd/ec2_instance.go b/cmd/ec2_instance.go index 1f88779..66f820e 100644 --- a/cmd/ec2_instance.go +++ b/cmd/ec2_instance.go @@ -42,7 +42,7 @@ var ec2InstanceCmd = &cobra.Command{ output := instance.GetOutput() output += "\n" + instance.GetLongOutput() - check.Exit(instance.GetStatus(), output) + check.ExitRaw(instance.GetStatus(), output) }, } diff --git a/cmd/ec2_instances.go b/cmd/ec2_instances.go index fdf5e61..106b4bf 100644 --- a/cmd/ec2_instances.go +++ b/cmd/ec2_instances.go @@ -54,7 +54,7 @@ var ec2InstancesCmd = &cobra.Command{ } } - check.Exit(instances.GetStatus(), summary+"\n"+instances.GetOutput()) + check.ExitRaw(instances.GetStatus(), summary+"\n"+instances.GetOutput()) }, } diff --git a/cmd/status_test.go b/cmd/status_test.go index 944fd53..a4dcbd4 100644 --- a/cmd/status_test.go +++ b/cmd/status_test.go @@ -14,7 +14,7 @@ func TestStatus_ConnectionRefused(t *testing.T) { out, _ := cmd.CombinedOutput() actual := string(out) - expected := "UNKNOWN - Get \"https://localhost" + expected := "[UNKNOWN] - Get \"https://localhost" if !strings.Contains(actual, expected) { t.Error("\nActual: ", actual, "\nExpected: ", expected) @@ -31,7 +31,7 @@ type StatusTest struct { func TestStatusCmd(t *testing.T) { tests := []StatusTest{ { - name: "status-ok", + name: "status-unknown", server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte(` @@ -51,7 +51,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "UNKNOWN - Could not determine status. Nothing so split into Slice", + expected: "[UNKNOWN] - Could not determine status. Nothing so split into Slice", }, { name: "status-ok", @@ -83,7 +83,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "OK - Event resolved for ec2 (eu-foobar-1)", + expected: "[OK] - Event resolved for ec2 (eu-foobar-1)", }, { name: "status-ok-no-items", @@ -103,7 +103,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "OK - No events for ec2 (eu-foobar-1)", + expected: "[OK] - No events for ec2 (eu-foobar-1)", }, { name: "status-ok-normal", @@ -129,7 +129,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "OK - Service ec2 is operating normally (eu-foobar-1)", + expected: "[OK] - Service ec2 is operating normally (eu-foobar-1)", }, { name: "status-warning", @@ -155,7 +155,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "WARNING - Performance issues for ec2 (eu-foobar-1)", + expected: "[WARNING] - Performance issues for ec2 (eu-foobar-1)", }, { name: "status-critical", @@ -181,7 +181,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "CRITICAL - Service disruption for ec2 (eu-foobar-1)", + expected: "[CRITICAL] - Service disruption for ec2 (eu-foobar-1)", }, { name: "status-informational", @@ -207,7 +207,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "--region", "eu-foobar-1"}, - expected: "WARNING - Information available for ec2 (eu-foobar-1)", + expected: "[WARNING] - Information available for ec2 (eu-foobar-1)", }, { name: "status-global-service", @@ -233,7 +233,7 @@ func TestStatusCmd(t *testing.T) { `)) })), args: []string{"run", "../main.go", "status", "-s", "iam", "--region", ""}, - expected: "WARNING - Information available for iam (Global)", + expected: "[WARNING] - Information available for iam (Global)", }, } diff --git a/go.mod b/go.mod index 0a1a5e7..1db3892 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,10 @@ module github.com/NETWAYS/check_cloud_aws -go 1.19 +go 1.21 require ( - github.com/NETWAYS/go-check v0.4.2 + github.com/NETWAYS/go-check v0.5.0 + github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 github.com/aws/aws-sdk-go v1.45.15 github.com/jarcoal/httpmock v1.3.1 github.com/spf13/cobra v1.7.0 @@ -15,11 +16,8 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect - github.com/mitchellh/go-ps v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/sirupsen/logrus v1.9.2 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 82bd0eb..57066e5 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ -github.com/NETWAYS/go-check v0.4.2 h1:qqmJxngW4v4rO6dgK3SmGk4qM47/HzTmvl2pp7/bmxA= -github.com/NETWAYS/go-check v0.4.2/go.mod h1:woBNNuHIRmULt+d4m0vTWhZV3dy0HiEr8Gu+6AzNhhY= +github.com/NETWAYS/go-check v0.5.0 h1:YahXTyveSOww3mTtKnvbsXZSk9kHi82mnvXHsNWx7AQ= +github.com/NETWAYS/go-check v0.5.0/go.mod h1:3G1p9ZCv41UcKirl+nZWne8oKVPUY5HbtyjRwGgyw6A= +github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41 h1:5PdguRs5fRgYvok56yQDXJssKXY91vNq6Tmhb4dFH/I= +github.com/NETWAYS/go-check-network/http v0.0.0-20230928080609-57070f836e41/go.mod h1:jZ62Y7P8/T/TqNy6I7RI/G9G9tXEcpuqrlkkO+xgCRE= github.com/aws/aws-sdk-go v1.45.15 h1:gYBTVSYuhXdatrLbsPaRgVcc637zzdgThWmsDRwXLOo= github.com/aws/aws-sdk-go v1.45.15/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -8,7 +10,6 @@ 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/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww= github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -17,14 +18,10 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g= github.com/maxatome/go-testdeep v1.12.0/go.mod h1:lPZc/HAcJMP92l7yI6TRz1aZN5URwUBUAfUNvrclaNM= -github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= -github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y= -github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -32,10 +29,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -54,11 +49,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -67,6 +59,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/ec2/mockdata_test.go b/internal/ec2/mockdata_test.go index c8332e7..470d562 100644 --- a/internal/ec2/mockdata_test.go +++ b/internal/ec2/mockdata_test.go @@ -1,7 +1,8 @@ package ec2_test import ( - "github.com/NETWAYS/go-check/http/mock" + "github.com/NETWAYS/go-check-network/http/mock" + "github.com/jarcoal/httpmock" )