Skip to content

Commit

Permalink
Upgrade to latest SDK version
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Chlebek <eric@sensu.io>
  • Loading branch information
echlebek committed Dec 7, 2023
1 parent 8ac510f commit 6e214d7
Show file tree
Hide file tree
Showing 7 changed files with 2,128 additions and 297 deletions.
2 changes: 1 addition & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"time"

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

Expand Down
61 changes: 51 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,58 @@
module github.com/sensu/sensu-check-log

go 1.12
go 1.21

require (
github.com/coreos/go-semver v0.3.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/sensu/core/v2 v2.20.0
github.com/sensu/sensu-plugin-sdk v0.18.0
github.com/stretchr/testify v1.8.4
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/echlebek/timeproxy v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/sensu/sensu-go/api/core/v2 v2.3.0
github.com/sensu/sensu-plugin-sdk v0.14.1
github.com/stretchr/testify v1.6.0
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/robertkrimen/otto v0.2.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sensu/sensu-api-tools v0.2.1 // indirect
github.com/sensu/sensu-go/types v0.13.0 // indirect
github.com/sensu/sensu-licensing/v2 v2.2.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.11 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2,289 changes: 2,048 additions & 241 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io/ioutil"

Check failure on line 8 in http.go

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest)

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"net/http"

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

func sendEvent(path string, outputEvent *corev2.Event) error {
Expand Down
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

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

type testHandler struct {
Expand Down
64 changes: 24 additions & 40 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"runtime"
"strings"

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

Expand Down Expand Up @@ -55,26 +55,24 @@ var (
},
}

options = []*sensu.PluginConfigOption{
&sensu.PluginConfigOption{
options = []sensu.ConfigOption{
&sensu.PluginConfigOption[string]{
Path: "log-file",
Env: "CHECK_LOG_FILE",
Argument: "log-file",
Shorthand: "f",
Default: "",
Usage: "Log file to check. (Required if --log-file-expr not used)",
Value: &plugin.LogFile,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "log-file-expr",
Env: "CHECK_LOG_FILE_EXPR",
Argument: "log-file-expr",
Shorthand: "e",
Default: "",
Usage: "Log file regexp to check. (Required if --log-file not used)",
Value: &plugin.LogFileExpr,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "log-path",
Env: "CHECK_LOG_PATH",
Argument: "log-path",
Expand All @@ -83,16 +81,15 @@ var (
Usage: "Log path for basis of log file regexp. Only finds files under this path. (Required if --log-file-expr used)",
Value: &plugin.LogPath,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "state-directory",
Env: "CHECK_LOG_STATE_DIRECTORY",
Argument: "state-directory",
Shorthand: "d",
Default: "",
Usage: "Directory where check will hold state for each processed log file. Note: checks using different match expressions should use different state directories to avoid conflict. (Required)",
Value: &plugin.StateDir,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[int]{
Path: "analyzer-procs",
Env: "CHECK_LOG_ANALYZER_PROCS",
Argument: "analyzer-procs",
Expand All @@ -101,16 +98,15 @@ var (
Usage: "Number of parallel analyzer processes per file.",
Value: &plugin.Procs,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "match-expr",
Env: "CHECK_LOG_MATCH_EXPR",
Argument: "match-expr",
Shorthand: "m",
Default: "",
Usage: "RE2 regexp matcher expression. (required)",
Value: &plugin.MatchExpr,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[int]{
Path: "warning-threshold",
Env: "CHECK_LOG_WARNING_THRESHOLD",
Argument: "warning-threshold",
Expand All @@ -119,16 +115,15 @@ var (
Usage: "Minimum match count that results in an warning",
Value: &plugin.WarningThreshold,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "warning-only",
Env: "CHECK_LOG_WARNING_ONLY",
Argument: "warning-only",
Shorthand: "W",
Default: false,
Usage: "Only issue warning status if matches are found",
Value: &plugin.WarningOnly,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[int]{
Path: "critical-threshold",
Env: "CHECK_LOG_CRITICAL_THRESHOLD",
Argument: "critical-threshold",
Expand All @@ -137,7 +132,7 @@ var (
Usage: "Minimum match count that results in an warning",
Value: &plugin.CriticalThreshold,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "critical-only",
Env: "CHECK_LOG_CRITICAL_ONLY",
Argument: "critical-only",
Expand All @@ -146,16 +141,15 @@ var (
Usage: "Only issue critical status if matches are found",
Value: &plugin.CriticalOnly,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[int64]{
Path: "max-bytes",
Env: "CHECK_LOG_MAX_BYTES",
Argument: "max-bytes",
Shorthand: "b",
Default: int64(0),
Usage: "Max number of bytes to read (0 means unlimited).",
Value: &plugin.MaxBytes,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "events-api-url",
Env: "CHECK_LOG_EVENTS_API_URL",
Argument: "events-api-url",
Expand All @@ -164,88 +158,78 @@ var (
Usage: "Agent Events API URL.",
Value: &plugin.EventsAPI,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "ignore-initial-run",
Env: "CHECK_LOG_IGNORE_INITIAL_RUN",
Argument: "ignore-initial-run",
Shorthand: "I",
Default: false,
Usage: "Suppresses alerts for any matches found on the first run of the plugin.",
Value: &plugin.IgnoreInitialRun,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "missing-ok",
Env: "CHECK_LOG_MISSING_OK",
Argument: "missing-ok",
Shorthand: "M",
Default: false,
Usage: "Suppresses error if selected log files are missing",
Value: &plugin.MissingOK,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[string]{
Path: "check-name-tamplate",
Env: "CHECK_LOG_CHECK_NAME_TEMPLATE",
Argument: "check-name-template",
Shorthand: "t",
Default: defaultNameTemplate,
Usage: "Check name to use in generated events",
Value: &plugin.CheckNameTemplate,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "disable-event-generation",
Env: "CHECK_LOG_CHECK_DISABLE_EVENT_GENERATION",
Argument: "disable-event-generation",
Shorthand: "D",
Default: false,
Usage: "Disable event generation, send results to stdout instead.",
Value: &plugin.DisableEvent,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "reset-state",
Env: "CHECK_LOG_RESET_STATE",
Argument: "reset-state",
Shorthand: "r",
Default: false,
Usage: "Allow automatic state reset if match expression changes, instead of failing.",
Value: &plugin.EnableStateReset,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "invert-thresholds",
Env: "CHECK_LOG_INVERT_THRESHOLDS",
Argument: "invert-thresholds",
Shorthand: "i",
Default: false,
Usage: "Invert warning and critical threshold values, making them minimum values to alert on",
Value: &plugin.InvertThresholds,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "verbose",
Argument: "verbose",
Shorthand: "v",
Default: false,
Usage: "Verbose output, useful for testing.",
Value: &plugin.Verbose,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "dry-run",
Argument: "dry-run",
Shorthand: "n",
Default: false,
Usage: "Suppress generation of events and report intended actions instead. (implies verbose)",
Value: &plugin.DryRun,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "output-matching-string",
Argument: "output-matching-string",
Shorthand: "",
Default: false,
Usage: "Include detailed information about each matching line in output.",
Value: &plugin.VerboseResults,
},
&sensu.PluginConfigOption{
&sensu.PluginConfigOption[bool]{
Path: "force-read-from-start",
Argument: "force-read-from-start",
Default: false,
Usage: "Ignore cached file offset in state directory and read file(s) from beginning.",
Value: &plugin.ForceReadFromStart,
},
Expand Down
5 changes: 2 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (
"strings"
"testing"

corev2 "github.com/sensu/sensu-go/api/core/v2"
sensu "github.com/sensu/sensu-go/api/core/v2"
corev2 "github.com/sensu/core/v2"
"github.com/stretchr/testify/assert"
)

type apiHandler struct {
t *testing.T
event *sensu.Event
event *corev2.Event
}

func (h apiHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
Expand Down

0 comments on commit 6e214d7

Please sign in to comment.