Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corev2 and other minor maintenance #26

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
os: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: 1.13.x
go-version-file: 'go.mod'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go 1.13
uses: actions/setup-go@v1
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.13
go-version-file: 'go.mod'
id: go
- name: Test
run: go test -v ./...
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/nixwiz/http-checks)
![Go Test](https://github.com/nixwiz/http-checks/workflows/Go%20Test/badge.svg)
![goreleaser](https://github.com/nixwiz/http-checks/workflows/goreleaser/badge.svg)
[![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu/http-checks)
![Go Test](https://github.com/sensu/http-checks/workflows/Go%20Test/badge.svg)
![goreleaser](https://github.com/sensu/http-checks/workflows/goreleaser/badge.svg)

# http-checks

Expand Down Expand Up @@ -297,7 +297,7 @@ using an asset, please consider doing so! If you're using sensuctl 5.13 with
Sensu Backend 5.13 or later, you can use the following command to add the asset:

```
sensuctl asset add nixwiz/http-checks
sensuctl asset add sensu/http-checks
```

If you're using an earlier version of sensuctl, you can find the asset on the [Bonsai Asset Index][3].
Expand All @@ -318,7 +318,7 @@ spec:
subscriptions:
- system
runtime_assets:
- nixwiz/http-checks
- sensu/http-checks
```

#### http-perf
Expand All @@ -335,7 +335,7 @@ spec:
subscriptions:
- system
runtime_assets:
- nixwiz/http-checks
- sensu/http-checks
output_metric_format: nagios_perfdata
output_metric-handlers:
- influxdb
Expand All @@ -355,7 +355,7 @@ spec:
subscriptions:
- system
runtime_assets:
- nixwiz/http-checks
- sensu/http-checks
```
#### http-get

Expand Down Expand Up @@ -402,7 +402,7 @@ For more information about contributing to this plugin, see [Contributing][4].

[1]: https://docs.sensu.io/sensu-go/latest/reference/checks/
[2]: https://docs.sensu.io/sensu-go/latest/reference/assets/
[3]: https://bonsai.sensu.io/assets/nixwiz/http-checks
[3]: https://bonsai.sensu.io/assets/sensu/http-checks
[4]: https://github.com/sensu/sensu-go/blob/master/CONTRIBUTING.md
[5]: https://github.com/ncr-devops-platform/nagiosfoundation
[6]: https://github.com/stedolan/jq
Expand Down
31 changes: 15 additions & 16 deletions cmd/http-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"strings"
"time"

corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-go/types"
corev2 "github.com/sensu/core/v2"
"github.com/sensu/sensu-plugin-sdk/sensu"
)

Expand Down Expand Up @@ -43,8 +42,8 @@ var (
},
}

options = []*sensu.PluginConfigOption{
{
options = []sensu.ConfigOption{
&sensu.PluginConfigOption[string]{
Path: "url",
Env: "CHECK_URL",
Argument: "url",
Expand All @@ -53,7 +52,7 @@ var (
Usage: "URL to test",
Value: &plugin.URL,
},
{
&sensu.PluginConfigOption[string]{
Path: "search-string",
Env: "CHECK_SEARCH_STRING",
Argument: "search-string",
Expand All @@ -62,7 +61,7 @@ var (
Usage: "String to search for, if not provided do status check only",
Value: &plugin.SearchString,
},
{
&sensu.PluginConfigOption[bool]{
Path: "insecure-skip-verify",
Env: "",
Argument: "insecure-skip-verify",
Expand All @@ -71,7 +70,7 @@ var (
Usage: "Skip TLS certificate verification (not recommended!)",
Value: &plugin.InsecureSkipVerify,
},
{
&sensu.PluginConfigOption[string]{
Path: "trusted-ca-file",
Env: "",
Argument: "trusted-ca-file",
Expand All @@ -80,7 +79,7 @@ var (
Usage: "TLS CA certificate bundle in PEM format",
Value: &plugin.TrustedCAFile,
},
{
&sensu.PluginConfigOption[bool]{
Path: "redirect-ok",
Env: "",
Argument: "redirect-ok",
Expand All @@ -89,7 +88,7 @@ var (
Usage: "Allow redirects",
Value: &plugin.RedirectOK,
},
{
&sensu.PluginConfigOption[int]{
Path: "timeout",
Env: "",
Argument: "timeout",
Expand All @@ -98,7 +97,7 @@ var (
Usage: "Request timeout in seconds",
Value: &plugin.Timeout,
},
{
&sensu.SlicePluginConfigOption[string]{
Path: "header",
Env: "",
Argument: "header",
Expand All @@ -107,7 +106,7 @@ var (
Usage: "Additional header(s) to send in check request",
Value: &plugin.Headers,
},
{
&sensu.PluginConfigOption[string]{
Path: "mtls-key-file",
Env: "",
Argument: "mtls-key-file",
Expand All @@ -116,7 +115,7 @@ var (
Usage: "Key file for mutual TLS auth in PEM format",
Value: &plugin.MTLSKeyFile,
},
{
&sensu.PluginConfigOption[string]{
Path: "mtls-cert-file",
Env: "",
Argument: "mtls-cert-file",
Expand All @@ -133,7 +132,7 @@ func main() {
check.Execute()
}

func checkArgs(event *types.Event) (int, error) {
func checkArgs(event *corev2.Event) (int, error) {
if len(plugin.URL) == 0 {
return sensu.CheckStateWarning, fmt.Errorf("--url or CHECK_URL environment variable is required")
}
Expand All @@ -148,7 +147,7 @@ func checkArgs(event *types.Event) (int, error) {
if len(plugin.TrustedCAFile) > 0 {
caCertPool, err := corev2.LoadCACerts(plugin.TrustedCAFile)
if err != nil {
return sensu.CheckStateWarning, fmt.Errorf("Error loading specified CA file")
return sensu.CheckStateWarning, fmt.Errorf("error loading specified CA file")
}
tlsConfig.RootCAs = caCertPool
}
Expand All @@ -160,15 +159,15 @@ func checkArgs(event *types.Event) (int, error) {
if len(plugin.MTLSKeyFile) > 0 && len(plugin.MTLSCertFile) > 0 {
cert, err := tls.LoadX509KeyPair(plugin.MTLSCertFile, plugin.MTLSKeyFile)
if err != nil {
return sensu.CheckStateWarning, fmt.Errorf("Failed to load mTLS key pair %s/%s: %v", plugin.MTLSCertFile, plugin.MTLSKeyFile, err)
return sensu.CheckStateWarning, fmt.Errorf("failed to load mTLS key pair %s/%s: %v", plugin.MTLSCertFile, plugin.MTLSKeyFile, err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
}

return sensu.CheckStateOK, nil
}

func executeCheck(event *types.Event) (int, error) {
func executeCheck(event *corev2.Event) (int, error) {

client := http.DefaultClient
client.Transport = http.DefaultTransport
Expand Down
2 changes: 1 addition & 1 deletion cmd/http-check/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"net/url"
"testing"

corev2 "github.com/sensu/core/v2"
"github.com/sensu/sensu-plugin-sdk/sensu"
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
18 changes: 9 additions & 9 deletions cmd/http-get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"time"

corev2 "github.com/sensu/sensu-go/api/core/v2"
corev2 "github.com/sensu/core/v2"
"github.com/sensu/sensu-plugin-sdk/sensu"
)

Expand All @@ -40,8 +40,8 @@ var (
},
}

options = []*sensu.PluginConfigOption{
{
options = []sensu.ConfigOption{
&sensu.PluginConfigOption[string]{
Path: "url",
Env: "CHECK_URL",
Argument: "url",
Expand All @@ -50,7 +50,7 @@ var (
Usage: "URL to get",
Value: &plugin.URL,
},
{
&sensu.PluginConfigOption[bool]{
Path: "insecure-skip-verify",
Env: "",
Argument: "insecure-skip-verify",
Expand All @@ -59,7 +59,7 @@ var (
Usage: "Skip TLS certificate verification (not recommended!)",
Value: &plugin.InsecureSkipVerify,
},
{
&sensu.PluginConfigOption[string]{
Path: "trusted-ca-file",
Env: "",
Argument: "trusted-ca-file",
Expand All @@ -68,7 +68,7 @@ var (
Usage: "TLS CA certificate bundle in PEM format",
Value: &plugin.TrustedCAFile,
},
{
&sensu.PluginConfigOption[int]{
Path: "timeout",
Env: "",
Argument: "timeout",
Expand All @@ -77,7 +77,7 @@ var (
Usage: "Request timeout in seconds",
Value: &plugin.Timeout,
},
{
&sensu.SlicePluginConfigOption[string]{
Path: "header",
Env: "",
Argument: "header",
Expand All @@ -86,7 +86,7 @@ var (
Usage: "Additional header(s) to send in check request",
Value: &plugin.Headers,
},
{
&sensu.PluginConfigOption[string]{
Path: "mtls-key-file",
Env: "",
Argument: "mtls-key-file",
Expand All @@ -95,7 +95,7 @@ var (
Usage: "Key file for mutual TLS auth in PEM format",
Value: &plugin.MTLSKeyFile,
},
{
&sensu.PluginConfigOption[string]{
Path: "mtls-cert-file",
Env: "",
Argument: "mtls-cert-file",
Expand Down
Loading