Skip to content

Commit

Permalink
Merge pull request #195 from NETWAYS/refactor/go-check-network
Browse files Browse the repository at this point in the history
Refactor to use go-check-network
  • Loading branch information
martialblog authored Sep 28, 2023
2 parents cab825c + 73a313f commit 7c79e36
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
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@v4
with:
go-version: 1.19
go-version: 1.21

- name: Test
run: go test -v ./...
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
2 changes: 1 addition & 1 deletion cmd/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ec2_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var ec2InstancesCmd = &cobra.Command{
}
}

check.Exit(instances.GetStatus(), summary+"\n"+instances.GetOutput())
check.ExitRaw(instances.GetStatus(), summary+"\n"+instances.GetOutput())
},
}

Expand Down
20 changes: 10 additions & 10 deletions cmd/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(`<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -51,7 +51,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -103,7 +103,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -129,7 +129,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -155,7 +155,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -181,7 +181,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -207,7 +207,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
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",
Expand All @@ -233,7 +233,7 @@ func TestStatusCmd(t *testing.T) {
</rss>`))
})),
args: []string{"run", "../main.go", "status", "-s", "iam", "--region", ""},
expected: "WARNING - Information available for iam (Global)",
expected: "[WARNING] - Information available for iam (Global)",
},
}

Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
)
17 changes: 5 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand All @@ -17,25 +18,19 @@ 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=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/ec2/mockdata_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down

0 comments on commit 7c79e36

Please sign in to comment.